Saturday, 20 February 2016

Custom Workflow Input and Output Parmeters in CRM

Custom Workflow Input and Output Parmeters in CRM


Today I got a requirement to create a task and assign it to the Manager of the Owner on the Parent Record. We can easily get the Owner value in the system workflow but not the Manager of the owner.

For this I had to write a custom workflow which will take Owner value as an Input Parameter and returns Manager of the Owner as an Output Parameter.

Here is the way to declare Input and Output Parameter in a Custom Workflow.

/// <summary>
/// Input Argument - SystemUser
/// </summary>
public InArgument<EntityReference> User { getset; }

/// <summary>
/// Output Arugument - Manager of the user.
/// </summary>
[Output("Manager of the user")]
public OutArgument<EntityReference> Manager { getset; }

And this the below code in the Workflow Execute Method.

// Get the Manager of the user.
EntityReference erfUser = User.Get<EntityReference>(executionContext);
Entity entityUser = service.Retrieve("systemuser", erfUser.Id, new ColumnSet(newstring[] { "parentsystemuserid" }));
Manager.Set(executionContext, (EntityReference)entityUser.Attributes["parentsystemuserid"]);

After this, just build your project and deploy it in CRM and use the same in the system workflow by passing the Owner value and it will give the Manager of the owner. 

In the same way, we can using CRM Custom Workflow for many business operations by using Input and Output Parameters.

I Hope this helps

Happy CRM'ing!


No comments:

Post a Comment

Note: only a member of this blog may post a comment.