1

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);

}

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

hkhan
  • 843
  • 2
  • 19
  • 45

1 Answers1

1

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

  • I changed the Xrm.Page to executionContext but I don't believe this is the issue. The fields autopopulate when the form is loaded. After a while I get "Check your money fields" and the PriceList field is wiped clean – hkhan Oct 18 '18 at 00:25
  • @hkhan deprecated means it will break in future. Did you try Business rules? Can you try debug/breakpoint & see what’s happening around reload? – Arun Vinoth-Precog Tech - MVP Oct 18 '18 at 00:28
  • i have tried debugging. The code works onLoad perfectly...after I get the "review your money field" warning, the script is not hit again. Just fyi, this is like an auto-refresh happening. I will try Business rules if I can't figure this out. – hkhan Oct 18 '18 at 00:33