Hi ,
I have created a custom workflow to assign multiple records to a Team
i am providing 2 input parameters -
1)FetchXml
2)Custom parameter
Basically i want to fetch all the records related to the primary entity.Foreg my entity name is "new_abc" and other entity is "new_xyz". i want to fetch all the records "new_abc" records that are related to "new_xyz".
I have a look up of "new_xyz" on my primary entity.
But i am not understanding why the primaryid is not getting set. it is throwing me error.
Please if anybody could help me in this.it will be a great help
Below is my code for the custom workflow -
public class Fetch : CodeActivity
{
[Input("Fetch XML")]
public InArgument<string> FetchXML { get; set; }
[Input("Team")]
[ReferenceTarget("team")]
public InArgument<EntityReference> Team { get; set; }
[Input("Entity Logical Name")]
public InArgument<string> EntityName { get; set; }
[Input("Attribute Name Input")]
public InArgument<string> AttributeName { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
try
{
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService tracer = executionContext.GetExtension<ITracingService>();
RowReturned.Set(executionContext, false);
Guid primaryId = Guid.Empty;
//To get Attribute from workflow
string attribute = AttributeName.Get(executionContext);
string entityName = EntityName.Get(executionContext);
//Creating entity of given type
Entity entity = new Entity(entityName);
EntityReference entityReference = (EntityReference)entity.GetAttributeValue<EntityReference>(attribute);
primaryId = entityReference.Id;
string fetch = FetchXML.Get<string>(executionContext);
fetch = String.Format(fetch, primaryId);
EntityCollection recordlist = service.RetrieveMultiple(new FetchExpression(fetch));
Count.Set(executionContext, recordlist.Entities.Count);
if (recordlist.Entities.Count > 0)
{
foreach (Entity item in recordlist.Entities)
{
// Create the Request Object and Set the Request Object's Properties
var request = new AssignRequest
{
Assignee = new EntityReference("team", Team.Get<EntityReference>(executionContext).Id),
Target = new EntityReference("mcg_locationaddress", item.Id)
};
// Execute the Request
service.Execute(request);
}
}
}
catch (Exception ex)
{
Helpers.Throw(String.Format("An error occurred in the {0} plug-in.",
this.GetType().ToString()),
ex);
}
}
Thanks,