locked
How to check for null attributes before referencing them after fetching it via fetchutility?? RRS feed

  • Question

  • Hi,

    I am fetching attributes using javascript on the OnChange event and filling up other fields. But i get an error if some attributes are null.

    Is there a way to check for null attributes before referencing them like in C# we have Entity.attributes.contains("fieldname") method to check for null values.

    Thanks


    Haris Adil e-Bizsoft

    Friday, May 25, 2012 3:18 PM

Answers

All replies

  • Hi,

    Are you getting value from database using javascript then you can check something like below

     var resultset= this.parent.JSON.parse(retrieveReq.responseText).d;
                if (retrievedAccount.<SchemaNameofField>!= null)

    {//fetch value

    }

    if you are reading value from fields directly you can try

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

    //fetchvalue

    }


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Friday, May 25, 2012 3:31 PM
    Moderator
  • Hi Mahender,

    I am using the following fetch utility

    http://www.crmsoftwareblog.com/2011/07/using-the-fetchxml-crm-2011-service-within-a-javascript-web-resource/

    I have got rid of the error by using try catch statement.

    Thanks for your reply. 


    Haris Adil e-Bizsoft


    • Edited by Harispk Friday, May 25, 2012 3:35 PM
    • Marked as answer by Harispk Tuesday, June 19, 2012 1:01 PM
    Friday, May 25, 2012 3:35 PM