Search code examples
argumentsdynamics-crm-2011dynamics-crmworkflow-activity

CRM 2011: Check for reference value in custom workflow assembly


I'm using the part of a coding in a customer workflow assembly in CRM 2011:

[Input("Organization input")]
[Output("Organization output")]
[ReferenceTarget("organization")]
public InOutArgument<EntityReference> OrgReference { get; set; }
[...]

In the definition of the workflow this input property is not set, that means no value has been selected, it's just empty.

When running the workflow, however, the code inside the if condition gets executed.

if (OrgReference != null)
{ //codeblock gets excuted here }

I would expect that the lines inside the code block is ignored.

Hence, what is the proper way to check if any workflow input properties are set or not?

Thanks, Michael


Solution

  • You have to call Contact.Get(executionContext) to get the actual value.

    if (OrgReference.Get(executionContext) != null)
    { //codeblock gets excuted here }