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)

Order product is not getting updated after being copied from quote product.

(0) ShareShare
ReportReport
Posted on by

Scenario:

I have written a plugin on "Post Operation" of salesorderdetail and the message is "Create". And in this plugin I am trying to update my custom field on salesorderdetail entity to some value.

Note: Both the entities "salesorderdetail" and "quotedetail" are having this custom field and created the mapping of these custom field.

After clicking on "create order" button on quote form, I want the custom field should get updated with my value and plugin should fire but it's not updating the field.

Please let me know if the scenario is not clear.

Any help will be appreciated!

Thanks in advance!

*This post is locked for comments

  • Radu Chiribelea Profile Picture
    6,667 on at

    Could you please share your code ?

  • Community Member Profile Picture
    on at

    try

               {

                   if (context.InputParameters["Target"] is Entity targetEntity)

                   {

                       if (targetEntity.Contains("somecustomfield"))  

                       {

                           if (context.Depth > 1)

                           {

                               var configurationResponse = SomeExternalAPi(passingvaluefromof "somecustomfield");

                               if (configurationResponse.Success)

                               {

                                   targetEntity.Attributes["customfield"] = configurationResponse.Content.Id.ToString();

                                   service.Update(targetEntity);

                               }

                               else

                               {

                                   targetEntity.Attributes["customfield"] = Guid.Empty.ToString();

                                   service.Update(targetEntity);

                               }

                           }

                       }

                   }

               }

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    From your code there is a condition  if (context.Depth > 1) then do the changes. I wonder if this isn't your issues, as if you are not within a loop the depth should always be 1

    Can you change that condition from  if (context.Depth > 1) to  if (!context.Depth > 1) and see if then your record gets updated?

    If you still see the issue, then I would also implement the tracing service and log messages for debug or use the plugin profiler

    Regards,

    Radu

  • Community Member Profile Picture
    on at

    Hi Radu Chiribelea, I have checked the depth and it's coming as 2 but still I have put my code in (!context.Depth > 1) block as you said, it's by passing.

    Please note that I have registered my plugin at: Pipeline stage - Post Operation, Message - Create, Execution mode - Synchronous.

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
TNJ_CRM_Team Profile Picture

TNJ_CRM_Team 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans