Reputation: 33
This is regarding CodeActivities in Microsoft CRM Workflows in Dynamics CRM 365. I need to fetch notes related to a workflow in my code activity. For that I need workflow Id of that workflow in my code activity. But there is only Workflow Instance Id in code activity context and not the Workflow Id. How can I get workflow Id form workflow Instance Id?
Upvotes: 2
Views: 3354
Reputation: 5446
You can use following code to get id of workflow using C#:
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
//Retrieve processid of current workflow instance
Entity asyncOperation = service.Retrieve("asyncoperation",
context.OperationId, new Microsoft.Xrm.Sdk.Query.ColumnSet("workflowactivationid"));
var workflowid = asyncOperation.GetAttributeValue<EntityReference>("workflowactivationid").Id;
After that you can use it to fetch notes.
Upvotes: 0
Reputation: 22836
Unfortunately you cannot get this directly.
Workaround is to setup an Input Parameter & send the Workflow name or even Workflow Id as a configuration item in designer. Read this Input param in codeactivity & retrieve the annotations associated with it.
This way, even if you have multiple workflows calling/executing the same codeactivity will work nicely.
Upvotes: 1