Hello guys,
I am currently working on some new CodeActivities for CRM 2011 and I got stuck with one particular problem.
The new Activity is supposed to execute a given Subworkflow every X Seconds for forever. Problem is, when we want to terminate the Workflow its status will stay on "Cancelling" and the activity will continue to execute the Subworkflow.
To counter that I wanted to add a check for the current status but I cant find a way to get my current AsyncOperationId.
My code currently looks like this, but I found out the "WorkflowInstanceId" does not match the AsyncOperationId (as I hoped) and I cant find anything regarding this isssue.
var currentStatusQuery = new QueryByAttribute() { EntityName = AsyncOperation.EntityLogicalName, ColumnSet = new ColumnSet("statecode", "statuscode") }; currentStatusQuery.AddAttributeValue("asyncoperationid", this.Context.WorkflowInstanceId); if ((this.Service.RetrieveMultiple(currentStatusQuery).Entities?.FirstOrDefault() as AsyncOperation)?.StatusCode?.Value == 22) { //... end this activity }
Looking forward to any help.
Greetings
Simon Schulte
*This post is locked for comments