Custom Workflow Input and Output Parmeters in CRM

Hi,
 
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.
 
///


/// Input Argument – SystemUser
///


[RequiredArgument]
[Input(“User”)]
[ReferenceTarget(“systemuser”)]
public InArgument<EntityReference> User { get; set; }

///


/// Output Arugument – Manager of the user.
///


[Output(“Manager of the user”)]
[ReferenceTarget(“systemuser”)]
public OutArgument<EntityReference> Manager { get; set; }

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(new string[] { “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.
 
Hope this helps.
 

Happy CRM’ing
Gopinath

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s