Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom Action Output Argument Entity Reference

(0) ShareShare
ReportReport
Posted on by

Hi all,

I'm working on a custom workflow called by a custom action. I'm wondering if when I have more than one output parameter, I must set all the parameters together every time that i want to set only one of them.

        [Input("CustomerExternalId")]
        public InArgument<String> CustomerExternalId { get; set; }

        [Output("Individual")]
        [ReferenceTarget("contact")]
        [Default(null)]
        public OutArgument<EntityReference> Individual { get; set; }

        [Output("Corporate")]
        [ReferenceTarget("account")]
        [Default(null)]
        public OutArgument<EntityReference> Corporate { get; set; }

I have these arguments. Now with this code the custom workflowk works fine:

   protected override void ExecuteInternal(LocalWorkflowContext context)
        {
            string customerexternalid = this.CustomerExternalId.Get(context.CodeActivityContext);

            if (customerexternalid != null)
            {
                var individualQuery = context.CrmContext.CreateQuery("contact").ToList().Where(c => c.GetAttributeValue<string>("etel_externalid") == customerexternalid).FirstOrDefault();
                var corporateQuery = context.CrmContext.CreateQuery("account").ToList().Where(c => c.GetAttributeValue<string>("etel_externalid") == customerexternalid).FirstOrDefault();

                if (individualQuery != null)
                {
                    EntityReference individualReference = new EntityReference(ProxyClasses.Individual.GetLogicalName(), individualQuery.Id);
                    this.Individual.Set(context.CodeActivityContext, individualReference);
      this.Corporate.Set(context.CodeActivityContext, null);
                }

                if (corporateQuery != null)
                {
                    EntityReference corporateReference = new EntityReference(ProxyClasses.Corporate.GetLogicalName(), corporateQuery.Id);
                    this.Corporate.Set(context.CodeActivityContext, corporateReference);
                    this.Individual.Set(context.CodeActivityContext, null);
                }
            }

Instead with the following it doesn't works (Exception: entity reference cannot have id and key attributes empty):

   protected override void ExecuteInternal(LocalWorkflowContext context)
        {
            string customerexternalid = this.CustomerExternalId.Get(context.CodeActivityContext);

            if (customerexternalid != null)
            {
                var individualQuery = context.CrmContext.CreateQuery("contact").ToList().Where(c => c.GetAttributeValue<string>("etel_externalid") == customerexternalid).FirstOrDefault();
                var corporateQuery = context.CrmContext.CreateQuery("account").ToList().Where(c => c.GetAttributeValue<string>("etel_externalid") == customerexternalid).FirstOrDefault();

                if (individualQuery != null)
                {
                    EntityReference individualReference = new EntityReference(ProxyClasses.Individual.GetLogicalName(), individualQuery.Id);
                    this.Individual.Set(context.CodeActivityContext, individualReference);
                }

                if (corporateQuery != null)
                {
                    EntityReference corporateReference = new EntityReference(ProxyClasses.Corporate.GetLogicalName(), corporateQuery.Id);
                    this.Corporate.Set(context.CodeActivityContext, corporateReference);
                }
            }

But I set the default value null, so why I'm doing wrong?

*This post is locked for comments

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Custom Action Output Argument Entity Reference

    Hi,

    you might try using 

    [Default(null, "contact")]

    [Default(null, "account")]

    Not sure it would help, but it might.

    https://msdn.microsoft.com/en-us/library/gg307375.aspx

    And, btw, try removing default completely..

    I am wondering if that's what it's complaining about (since it might be creating en entity reference because of that default, but, since you are using null, that entity reference does not have an id)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans