locked
Question on formatting related to data.d on ODATA Rest array return RRS feed

  • Question

  • I have an ODATA Rest endpoint query function that gets the data I need.

    My problem is that I am having difficulty getting the desired data out of data.d and displaying it in an alert.

    The problem code snippet to focus on is shown below:

    var result_data = data.d;
    alert(result_data["new_s_bingolicensetypeId"]);
    
     

    In the Visual Studio debugger, look specifically on right portion of the screen, what looks like:

    • data.d
    • array element [0]
    • property new_s_bingolicensetypeId

    As someone new to development and CRM, I am certain my problem is one of syntax. I am hoping someone can show me how to write alert(result_data[0]."new_s_bingolicensetypeId") so my alert actually returns 5c87c42e-af6e-e511-adaa-000c29d70c71 instead of an alert box that says "Undefined"

    I have to be missing something from a syntax standpoint. Any help would be greatly appreciated. 


    Saturday, October 17, 2015 7:52 PM

Answers

  • You just need to do

    alert(data.d.results[0].new_s_bingolicensetypeId);

    but you should check first if you have elements inside the array before access them:

    something like

    if (data.d.results != null && data.d.results.length > 0) {

    alert(data.d.results[0].new_s_bingolicensetypeId);

    }


    My blog: www.crmanswers.net - CRM Theme Generator

    • Marked as answer by ACECORP Sunday, October 18, 2015 4:48 AM
    Sunday, October 18, 2015 3:14 AM

All replies

  • I am closing in, but still can't seem to figure out how to get ahold of the data I need which is 5c87c42e-af6e-e511-adaa-000c29d70c71

    I am hoping someone can explain how to access this data.

     

    Saturday, October 17, 2015 8:40 PM
  • You just need to do

    alert(data.d.results[0].new_s_bingolicensetypeId);

    but you should check first if you have elements inside the array before access them:

    something like

    if (data.d.results != null && data.d.results.length > 0) {

    alert(data.d.results[0].new_s_bingolicensetypeId);

    }


    My blog: www.crmanswers.net - CRM Theme Generator

    • Marked as answer by ACECORP Sunday, October 18, 2015 4:48 AM
    Sunday, October 18, 2015 3:14 AM
  • That did it! Thanks so much!
    Sunday, October 18, 2015 4:48 AM