首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让团队用户从团队中获得输入

如何让团队用户从团队中获得输入
EN

Stack Overflow用户
提问于 2013-03-05 17:12:06
回答 1查看 2.5K关注 0票数 3

我试图构建我的第一个WorkFlow,从输入一个团队,并让所有的用户在这个团队中,并将他们放在一个客户关系管理电子邮件的" to“字段。

我的第一个挑战是检索兼容的输入类。例如,类:XrmDataContextTeamMembershipEmail(email.Subject)编译器没有识别它们。

我一直在尝试使用我在互联网上找到的代码,但对我来说不太清楚。

代码语言:javascript
复制
    [Input("Team Name")]
    [Default("Case Team")]
    public InArgument<string> CaseTeam { get; set; }

    [Output("Date time")]
    public OutArgument<DateTime> TaskDueDate { get; set; }
      protected override void Execute(CodeActivityContext executionContext)
    {
        try
        {
            // Create the tracing service
            ITracingService tracingService = executionContext.GetExtension<ITracingService>();

            // Create the context
            IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

            // Create the Organiztion service
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            // Get the target entity from the context
            Entity target = (Entity)context.InputParameters["Target"];

            // Prepare DataContext by using AutoGenerated cs file
            XrmDataContext datacontext = new XrmDataContext(service);

            // Get the Team Name from the Workflow input parameter
            string teamName = CaseTeam.Get<string>(executionContext);

            // Get the Team Id from the Team Name
            var team = (from t in datacontext.TeamSet
                        where t.Name == teamName
                        select new { t.TeamId }).First();

            // Get all the members of the team to send email
            List<Entity> teamMembers = (from t in datacontext.TeamMembershipSet
                                                where t.TeamId == team.TeamId
                                                select t).ToList();

            // Send email to memebers of the team
            CreateEmail(service, teamMembers, target, context.InitiatingUserId);

            // Set the Task DueDate to 2 days by using Output Parameter
            TaskDueDate.Set(executionContext, DateTime.Now.AddDays(2));

        }
        catch (SoapException ex)
        {
            // Add the SoapException message in event log
            EventLog.WriteEntry("code error", "Error occured in " + ex.Detail.InnerText.ToString(), EventLogEntryType.Error);
        }
        catch (Exception exe)
        {
            // Add the GeneralException message in event log
            EventLog.WriteEntry("code error", "Error occured in " + exe.InnerException.ToString(), EventLogEntryType.Error);
        }
    }

    public static void CreateEmail(IOrganizationService service, List<Entity> teamMembers, Entity caseEntity, Guid loggedinUser)
    {
        // Create Email 
        Entity email = new Entity("email");

        // Set the from user of the email to Logged in user
        Entity fromParty = new Entity("activityparty"); 
        fromParty.Id = new EntityReference(SystemUser.EntityLogicalName, loggedinUser);

        List<Entity> toPartyList = new List<Entity>();

        // Add the Activity party for each member in the team
        foreach (TeamMembership user in teamMembers)
        {
            ActivityParty toParty = new ActivityParty();
            toParty.PartyId = new EntityReference(SystemUser.EntityLogicalName, user.SystemUserId.Value);
            toPartyList.Add(toParty);
        }

        // Add the subject and description by concating the case ticket number
        email.Attributes.Add("Case " + caseEntity.Attributes["ticketnumber"].ToString() + " Added. Please review");
        email.Description = "Case " + caseEntity.Attributes["ticketnumber"].ToString() + " Added. Please review";

        // Add To and From users to email
        email.To = toPartyList.ToArray();
        email.From = new[] { fromParty };

        // Set the case regarding
        email.RegardingObjectId = new EntityReference(Incident.EntityLogicalName, caseEntity.Id);

        // Create email
        Guid emailId = service.Create(email);

        SendEmailRequest sendRequest = new SendEmailRequest();
        sendRequest.EmailId = emailId;
        sendRequest.TrackingToken = string.Empty;
        sendRequest.IssueSend = true;

        // Send the email message.
        service.Execute(sendRequest);
    }
EN

回答 1

Stack Overflow用户

发布于 2013-03-05 21:46:57

您必须用CrmSvcUtil生成以获得该类的引用。拿个。我不知道你是否在关注任何一篇文章,但你可以查看这个文章

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15229971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档