web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Problem with custom workflow to update salesorederdetail

(0) ShareShare
ReportReport
Posted on by

I am trying to write a customer workflow to update two custom fields on salesorderdetail and I'm getting an error message can anyone help and suggest how to correct the code.  

'product' entity doesn't contain attribute with Name = 'new_SupplierPO' and NameMapping = 'Logical'.

The custom fields definitely exist in salesorderdetail.

    public class updateorderline : CodeActivity
    {
        [Input("Supplier Purchase Order")]
        [RequiredArgument]
        [ReferenceTarget("new_supplierpo")]
        public InArgument<EntityReference> POfromorder { get; set; }
        [Input("Order Line")]
        [RequiredArgument]
        [ReferenceTarget("salesorderdetail")]
        public InArgument<EntityReference> salesorderdet { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            IWorkflowContext workflowcontext = context.GetExtension<IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = context.GetExtension<IOrganizationServiceFactory>();
            IOrganizationService service = serviceFactory.CreateOrganizationService(workflowcontext.InitiatingUserId);
            var prodid = salesorderdet.Get<EntityReference>(context).Id;
            if (prodid != null)
            {
                //update regarding product
                Entity product = new Entity("product");
                product.Id = prodid;
                product["new_SupplierPO"] = POfromorder.Get<EntityReference>(context);
                product["new_AddtoPO"] = false;
                service.Update(product);
            }
        }
    }
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    double check is your product entity has this field "new_SupplierPO" and new_AddtoPO ? if yes,

    make it lower case.

    new_SupplierPO = new_supplierpo

    new_AddtoPO = new_addtopo

  • Community Member Profile Picture
    on at

    I’ve already tried that.  Didn’t work

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    can you screen shot the field setting in CRM ?

  • SpkyJohn75 Profile Picture
    30 on at

    7801.Capture2.PNG

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    From the picture itself, I am assuming you didnt change the relationship name, it seems this field is in Order Product and reference to Supplier PO.

    Order Product is not equal to Product.

    So, change below part into

     Entity product = new Entity("salesorderdetail");

  • Community Member Profile Picture
    on at

    Well spotted Wei! I changed that and changed back the fields so no capitalisation

    new_SupplierPO = new_supplierpo

    new_AddtoPO = new_addtopo

    That fixed it.  Thank you so much Fun Wei Jie!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans