Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Javascript to copy field value to other field on Order Product

Posted on by 1,320

I created a new field (Field B) on the Order Product entity and I want to automatically pass over the value of an existing field (Field A) to this new field (both fields are on the order product). I was told that javascript is needed for this because we are on 2015 and business rules are not yet introduced for order products, and you cannot update order product fields via workflows. I want these values to pass upon create of order products. 

Also, sometimes the values on Field A will get removed (due to our integration) but I do NOT want the value on Field B to be removed after it has been set.

Can someone please help on getting me started with this? Thanks.

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Javascript to copy field value to other field on Order Product

    Yes, that seems to be how it is

  • epark06 Profile Picture
    epark06 1,320 on at
    RE: Javascript to copy field value to other field on Order Product

    I see, then I guess the javascript won't work for this case because most order products will not be opened in their own window, and will only be viewed from the Order form after it has been converted from a quote. Does this mean plugin is the best option?

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Javascript to copy field value to other field on Order Product

    Hi,

     for the new records, your javascript might be like this:

    function Form_OnSave()

    {

     if(Xrm.Page.getAttribute("<new_field">).getValue() == null)

     {

     Xrm.Page.getAttribute("<new_field>").setValue(Xrm.Page.getAttribute("<old_field">).getValue());

      }

    }

     You can add that script as a form OnSave handler

     For the existing records, please go with Guido's answer (console app). Or you could set up an SSIS job to update existing records (but, again, might be too involved)

     Another option - having added this script, go to each an every order product.. the script will run, update the field, and you'll be able to save the record.

    PS.  However, just like we discussed before.. this will only work with the javascript if you ever open those order products in their own window (if you convert a quote, for example, this won't happen, so javascript won't run)

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans