Input-Output Parameters for Custom Workflow Assembly in MS Dynamics CRM

For Dynamics CRM, workflow is a robust tool that helps them to write complex business logic processes without creating single programming line. In this article, developers will explain the way they parameterize their workflow.

f:id:aegissofttech:20200728214439p:plain

Introduction:

Workflow is very powerful tool which highly used in MS Dynamics CRM trends. You can write complex business logic processes without writing single line of programming. You can use “if then else” condition, create or update record, send email, wait condition, change status of record and many more other operations.

To make the workflow more powerful, Microsoft providing on more functionality in which you can add your custom code assembly in workflow. For developer, customer workflow is more sufficient way to achieve really difficult specifications. Also, in this custom code, you can add input and output parameters same as some method parameters.

Today we are discussing about Input – Output parameters which can be used in custom workflow assembly to simplify the business logic.

Description about Problem:

How to use Input – Output parameters in CRM custom workflow assembly?

Solution:

Small things make big difference. Yes this is what you can say about Input – Output parameters. Input parameter will help workflow to get the value which is assigned into related parameter.

You can get the value of related parameter by using below code.

“executionContext.GetValue(this.ParameterName)”

You can declareInput parameters in your custom workflow assembly as listed data below.

Input Parameters

Using “Input” keyword, we can declare input parameter.

DefaultAttribute

If you want to use default value for an attribute, use “Default” keyword and define the value for the parameter.

  • Bool

 [Input("Bool input")]

 [Default("True")]

 publicInArgument Bool { get; set; }

  • DateTime

 [Input("DateTime input")]

 [Default("2016-11-11T05:05:10Z")]

 publicInArgument Date { get; set; }

  • Decimal

 [Input("Decimal input")]

 [Default("98.37")]

 publicInArgument Decimal { get; set; }

  • Double

 [Input("Double input")]

 [Default("678.5")]

 publicInArgument Double { get; set; }

  • Integer

 [Input("Int input")]

 [Default("8954")]

 publicInArgumentInt { get; set; }

  • Money (Currency)

 [Input("Money input")]

 [Default("337.4")]

 publicInArgument Money { get; set; }

  • OptionSetValue

 [Input("OptionSetValue input")]

 [AttributeTarget("account", "industrycode")]

 [Default("1")]

 publicInArgumentOptionSetValue { get; set; }

NOTE: Attribute Target must specify the entity and attribute being referenced.

  • String

 [Input("String input")]

 [Default("My name as default string value")]

 publicInArgument String { get; set; }

  • Entity Reference

 [Input("EntityReference input")]

 [ReferenceTarget("contact")]

 [Default("4AA33D4F-53DF-E511-80C5-002481D2A0DB", "contact")]

 publicInArgumentContactReference { get; set; }

NOTE: Reference Target attribute must specify the type of entity being referenced.

Required Argument Attribute

You can also set Parameter as required using below piece of code.
System.Activities.RequiredArgumentAttribute class can be used to specify that the input parameter is required.

 [RequiredArgument]

 [Input("Update next Anniversary date for")]

 [ReferenceTarget("contact")]

 publicInArgument Contact { get; set; }

Output Parameters

Using “Output” keyword, we can declare output parameter. The output parameter highlight of custom Workflow assembly is intriguing. The Output parameter defined in the custom Workflow assembly becomes available in the CRM Workflow window to analyze performance. You can utilize this yield parameter in any of the Workflow steps.

You can use Output parameter in various ways like in Wait/If condition block or in Create/Update etc. You can declare output parameters in your custom workflow assembly as listed data below.

//this is the name of the parameter that will be returned back to the workflow

 [Output("Credit Score")]

//this line identifies the specific attribute which will be passed back to the workflow

 [AttributeTarget(CustomEntity, "new_creditscore")]

//this line declares the output parameter and declares the proper data type of the parameter being passed back.

 publicOutArgumentCreditScore {get;set;}

You can also declare parameter as Input and Output both.

In the accompanying code model, IntParameter is the input as well as the yield parameter.

 [Input("Int input")]

 [Output("Int output")]

 [Default("1234")]

 publicInOutArgumentIntParameter { get; set; }

A few sorts, for example, EntityReference and OptionSetValue, require extra attributes apart from the Input, Output, and Default properties.

The other attributes are: ReferenceTarget and AttributeTarget. The accompanying example shows the meaning of a parameter of the EntityReferencetype.

 [Input("EntityReference input")]

 [Output("EntityReference output")]

 [ReferenceTarget("account")]

 [Default("3B036E3E-94F9-DE11-B508-00155DBA2902", "contact")]

 publicInOutArgumentContactReference { get; set; }

The Wrap Up

It is hard to deal with some custom business rationale in manual work process. In that situation custom work process assembly is a genuine saint! You can use input parameter to minimize your code and also user the output parameter in next step of your workflow.

Once you will start using Input – Output parameter, you will really like it to manage the code in proper manner and lot of extra efforts to manage the value will remove.

Once you parameterize the workflow in CRM, you can achieve difficult specifications with an ease. The developers of Microsoft Dynamics CRM Development Company have shared this article to make you understand why workflow matters to them and why it has to be parameterized.