locked
Error: The value of the property 'XYZ' is null or undefined, Not a Function Object RRS feed

  • Question

  • Hello, 

    I'm running into an error creating a calculated field in the project module of CRM 2011. I've created 2 new fields and am using one existing field(I've included information below):

    New Fields:

    Display Name: rate  

    Name: new_rate

    Data type: Currency

    ******************************

    Display Name: Budgeted

    Name: new_budgetedamount

    Data Type: Currency

    ***************************

    Existing field:

    Display Name: Service Hours

    Name: new_servicehours

    Data Type: Decimal with 2 precision

    **************************

    In my code I setup a simple on change event based on when the rate field changes using the following script:

    function calculate()

    {

    var Rate = Xrm.Page.getAttribute('new_rate').getValue();
    var Service Hours = Xrm.Page.getAttribute('new_servicehours').getValue();

    if(Rate==null)return;
    if(Service Hours==null)return;

    var Budgeted = Rate * Service Hours;

    Xrm.Page.getattribute('new_budgetedamount').setValue(Budgeted);

    }

    When the rate is changed I get the following error:

    There was an error with this fields customized event.

    Field:new_rate

    Event:onchange

    Error:The value of the property 'calculate' is null or undefined, not a Function object. 

    Any help would be great! 


    Thank you, 

    Eric 


    • Edited by Eric Brady Wednesday, May 23, 2012 7:33 PM
    Wednesday, May 23, 2012 7:32 PM

Answers

  • Schema name must be in " double quotes. and variable names could not contain spaces
    Please use the following code
    function calculate()
    {
    var Rate = Xrm.Page.getAttribute("new_rate").getValue();
    var ServiceHours = Xrm.Page.getAttribute("new_servicehours").getValue();

    if(Rate != null && ServiceHours != null)

    {
    var Budgeted = Rate * ServiceHours;

    Xrm.Page.getAttribute("new_budgetedamount").setValue(Budgeted);
    }
    }

    If you need more information please let me know


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!




    • Edited by MubasherSharif Wednesday, May 23, 2012 8:21 PM
    • Marked as answer by Eric Brady Wednesday, May 23, 2012 8:47 PM
    Wednesday, May 23, 2012 8:11 PM

All replies

  • Schema name must be in " double quotes. and variable names could not contain spaces
    Please use the following code
    function calculate()
    {
    var Rate = Xrm.Page.getAttribute("new_rate").getValue();
    var ServiceHours = Xrm.Page.getAttribute("new_servicehours").getValue();

    if(Rate != null && ServiceHours != null)

    {
    var Budgeted = Rate * ServiceHours;

    Xrm.Page.getAttribute("new_budgetedamount").setValue(Budgeted);
    }
    }

    If you need more information please let me know


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!




    • Edited by MubasherSharif Wednesday, May 23, 2012 8:21 PM
    • Marked as answer by Eric Brady Wednesday, May 23, 2012 8:47 PM
    Wednesday, May 23, 2012 8:11 PM
  • Your script has syntax errors in it:

    var Service Hours = Xrm.Page.getAttribute('new_servicehours').getValue();
    
    ...
    
    if(Service Hours==null)return;
    
    var Budgeted = Rate * Service Hours;
    

    Variable names cannot have spaces in them; and you should have spaces between identifiers and equality signs (==):

    var ServiceHours = Xrm.Page.getAttribute('new_servicehours').getValue();
    
    ...
    
    if(ServiceHours == null)return;
    
    var Budgeted = Rate * ServiceHours;
    

    If your javascript has syntax errors, the browser's parser cannot parse the script, so none of it will work - hence your function is undefined.

    You should get used to using a javascript syntax checker such as jslint.com to validate your script.


    --pogo (pat) @ pogo69.wordpress.com

    Wednesday, May 23, 2012 8:18 PM
  • Thanks a bunch!! that did the trick!
    Wednesday, May 23, 2012 8:48 PM