We have recently modified a process where the workflow has to check for a particular time range (done through a custom activity) and if the time at the moment is within the range being checked, the process waits for 30 minutes. At the end of those 30 minutes, it submits itself as a child workflow.
This worked as expected, but we ran into an issue: The remainder of the process needs the user identity to correctly process the entity information. When the process runs normally without the wait timeout, there are no issues. But when it falls in the timeout, and then submits itself as the child workflow, the user identity is changed to that of the workflow owner.
That means that if the owner of the process is, say, your local friendly IT guy, that’s who CRM thinks is running the process, and thus any user-based validations will fail.
The solution for this was to have code in the custom activity that looks for the creator of the entity, and then use that as the user ID needed to execute the user identity-related code. How? We created a function for retrieving the entity owner, and we pass the primary entity ID, as follows:
This is the code that returns the owner information, and we take it from there:
private Guid GetEntityOwner(Guid entityId)
var myEntity = OrganizationService.Retrieve("new_myentity", entityId, new ColumnSet("createdby"));
var ownerReference = myEntity.GetAttributeValue<EntityReference>("createdby");
That fixed the problem and now we get the correct owner for the process to finish successfully.