Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM 2011 - Custom Workflow activity to retrieve teamMembers as an Output parameter

$
0
0

Hi All,

Could anybody please help me when a record is created custom workflow activity that takes TEAM an input parameter in the first step and passes an output parameter value as all TEAM MEMBERS of that TEAM to another step in the workflow ?

So that I can configure that output onto TO field in sending emails to all the team members.

I have tried to create the following workflow activity that should get the team members of a team:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.Web.Services.Protocols;
using System.Diagnostics;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;
using Xrm;
namespace Custom.Workflow.Activities
{    
    public class GetListofTeamMembers : CodeActivity
    {       
        [Input("To: Team")]
        [ReferenceTarget(Team.EntityLogicalName)]
        public InArgument<EntityReference> LookupToTeam { get; set; }
        [Output("To:TeamMembers")]
        public OutArgument<EntityCollection> TeamMembers { 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 = LookupToTeam.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<TeamMembership> teamMembers = (from t in datacontext.TeamMembershipSet
                                                    where t.TeamId == team.TeamId
                                                    select t).ToList();
            }
            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);
            }
        }}}



Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>