简体   繁体   中英

Unable to set Price List and Currency on Quote Via Javascript in Dynamics CRM online

I wrote some javascript that loads values of price list and currency on Quotes entity. This used to work fine in CRM Online 8.2 but since upgrade to 9.0 I have started having a weird issue.

So on OnLoad of the form the script runs and sets the values as it should. If I wait on the quote form for like 20 seconds the form auto-refreshes which I guess is a CRM functionality, but after refreshing the Price List is wiped out and I see it clears the value of my currently selected price list.

And then the user has to manually set it or refresh the page. This is my code:

function SetCurrency() 
{
    var object = new Array();

    object[0] = new Object();

    object[0].id = "<object_id>";

    object[0].name = "US Dollar";

    object[0].entityType = "transactioncurrency";

    Xrm.Page.getAttribute("transactioncurrencyid").setValue(object);

}
function SetPriceList() {
    var object1 = new Array();

    object1[0] = new Object();
    object1[0].id = "<object_id>";
    object1[0].name = "Default Price List";
    object1[0].entityType = "pricelevel";
    Xrm.Page.getAttribute("pricelevelid").setValue(object1);

}

PS the whole code is the same except that I removed the actual object.id's

If you are just setting the default values, I would recommend to use Business rules.

The currency can be set in user personal options, that will make sure transactioncurrencyid is auto populated in form load. Reference

On a side note, Xrm.Page is deprecated in v9 and you should be looking for code change to supported executionContext.getFormContext() . Read more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM