locked
JS file does not work RRS feed

  • Question

  • I have added two new fields to the Account entity: triggerfield and calculatedfield. the triggerfield taks in a number multiplies it by 3.14 and stores it into the calculatedfield, at least it should. but for some reason it throws an unknow error.

    I have added the js file to crm libraries and the attributes names match between CRM and my js file. Can someone please tell me what i am doing wrong?

    here is the code:

    function UpdateField(){
    var trig = Xrm.Page.getAttribute("new_triggerfield");
    var dest = Xrm.Page.getAttribute("new_calculatedfield");

    // Test to make sure the trigger field has a value, this will return null if blank.
    if(trig.getValue() != null){
    var newValue = trig.getValue() * 3.14;

    Xrm.Page.getAttribute("new_calculatedfield").setSubmitMode("always"); 

    dest.setValue(newValue);
    }
    }

    Monday, June 9, 2014 9:46 PM

All replies

  • what is the data type you selected while creating these fields ?? what error you are getting ?? where are you calling this function ??

    try to use below

    var newValue = parseInt(trig.getValue()) * 3.14;


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Tuesday, June 10, 2014 4:36 AM
    Moderator
  • They are Floating Point Number numbers. 

    Here is the error message:

    There was an error with this field's customized event.
    Field:new_triggerfield
    Event:onchange
    Error:undefined

    Im calling it OnChange for triggerfield.

    var newValue = parseInt(trig.getValue()) * 3.14; This did not change anything, its still throwing the same message.

    Tuesday, June 10, 2014 2:59 PM
  • Have you tried debugging your JavaScript? You may be able to get detailed error message.
    Tuesday, June 10, 2014 3:11 PM
  • Hi,

    Can you try with:

    var newValue = parseFloat(trig.getValue())*3.14;


    Admin QuikView Solution for CRM 2013

    Tuesday, June 10, 2014 3:12 PM
  • Running the debugger does not give me a different error, but when i evaluate it, i get this:

    Xrm.Page.getAttribute("new_calculatedfield").setSubmitMode("always");
    TypeError: Cannot read property 'setSubmitMode' of null
    1. message"Cannot read property 'setSubmitMode' of null"
    2. stack(...)
    3. get stackfunction () { [native code] }
      1. argumentsnull
      2. callernull
      3. length0
      4. name""
      5. prototypeObject
      6. __proto__function Empty() {}
      7. <function scope>
    4. set stackfunction () { [native code] }
    5. __proto__Error

    Tuesday, June 10, 2014 5:02 PM
  • And no parseFloat does not make a diffrence.
    Tuesday, June 10, 2014 5:04 PM
  • The error message is self explanatory. The attribute "new_calculatedfield" does not exist. Make sure you have that attribute on the form.
    • Proposed as answer by Ahmad Pirani Tuesday, June 10, 2014 5:15 PM
    Tuesday, June 10, 2014 5:15 PM
  • As far as i can tell it is there. it has a type, its on the form for an input.....

    I reran and disabled the function and it gave me "refused to set unsafe header content-length" error from the global source code. 

    I assume this means i did not enable/define something right?

    Tuesday, June 10, 2014 5:19 PM
  • Can you try to use like below and see if you are still getting error, also assuming this is a readonly field correct ??

    if(Xrm.Page.getAttribute("new_calculatedfield")!=null){ 

    Xrm.Page.getAttribute("new_calculatedfield").setSubmitMode("always"); }


    Our Website| Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Wednesday, June 11, 2014 7:09 AM
    Moderator
  • first set the value then do force submit dest.setValue(newValue); Xrm.Page.getAttribute("new_calculatedfield").setSubmitMode("always");

    Regards Faisal

    Wednesday, June 11, 2014 11:06 AM
  • set the value BEFORE setting the submit mode so that it is not null.

    also, to avoid goofy errors use the more desirable lambda expressed "UpdateField = function () {...}"

    Wednesday, June 11, 2014 1:37 PM