BLOGs
Web Development
Published December 02nd, 2016 by

How Dynamics CRM Developers Parameterize Their Workflow?

For dynamics CRM developers, 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.

Introduction:

Workflow is very powerful tool which highly used in MS Dynamics CRM. 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.

CRM

Description about Problem:

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

Solution:

Small things which 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 feature of custom Workflow assembly is very interesting. The Output parameter defined in the custom Workflow assembly, becomes available in the CRM Workflow window. You can use this output 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 following code example, IntParameter is the input as well as the output parameter.

[Input("Int input")]
 [Output("Int output")]
 [Default("1234")]
 publicInOutArgumentIntParameter { get; set; }

Some types, such as EntityReference and OptionSetValue, require additional attributes apart from the Input, Output, and Default attributes.

The additional attributes are: ReferenceTarget and AttributeTarget. The following sample shows the definition of a parameter of the EntityReferencetype.

[Input("EntityReference input")]
 [Output("EntityReference output")]
 [ReferenceTarget("account")]
 [Default("3B036E3E-94F9-DE11-B508-00155DBA2902", "contact")]
 publicInOutArgumentContactReference { get; set; }

Conclusion:

It is difficult to manage some custom business logic in manual workflow in that circumstance custom workflow assembly is a real hero! 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. Dynamics CRM developers have shared this article to make you understand why workflow matters to them and why it has to be parameterized.

Ethan Millar

Technical Writer at Aegis Softtech
Having more than 6+ years of experience to write technical articles especially for Hadoop, Big Data, Java, CRM and Asp.Net at Aegis Softtech.

Our rankings are completely independent, transparent, and community driven; they are based on user reviews and client sentiment. These web development companies had to earn their way up and didn't just pay their way up.

View Rankings of Best Web Development Companies