Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Accessing oData results and applying them to field

Posted on by Microsoft Employee

Hi All,

Quick question: I'm using oData to access some records and I have these stored as follows:

var results = JSON.parse(req.responseText).d.results;
if (results != null && results.length > 0) {
alert = whatgoeshere??
}

Can anyone reveal the syntax for accessing the results?  I.e. results[0].etc.etc

Thanks a million.

PS. End goal will be to call the following:

Xrm.Page.getAttribute("new_clientalerts").setValue(alert);


*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Accessing oData results and applying them to field

    Guido, thanks.  Bas, thanks for your suggestions.

    I'm sure you'll help me again soon :)

    Cheers guys

  • Bas van de Sande Profile Picture
    Bas van de Sande 4,383 on at
    RE: Accessing oData results and applying them to field

    Hi Guido,

    you're right. I overlooked the fact that Lee was using a reserved keyword..

    Bas

  • Bas van de Sande Profile Picture
    Bas van de Sande 4,383 on at
    RE: Accessing oData results and applying them to field

    Hi Lee,

    can you show me how results[0] looks like?

    can you also show me how alertArray looks like?

    you're pretty close at this point.

    Bas

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Accessing oData results and applying them to field

    Hi Bas,

    Thanks for your response.  I had found the debugging technique shortly after I posted here actually but thanks for the suggestions, it will help others.

    What I currently have is:

            var results = JSON.parse(req.responseText).d.results;
            if (results != null && results.length > 0) {
                alertArray = results[0];
                alert = alertArray.new_Alert;
            }

    However, when I hover over the 'alert' variable, it's 'null' - I get the following:
    18032.Capture.PNG

    even though the content 'alertArray.new_Alert' contains the string "test alert"

    18032.Capture.PNG

    Can you shed any light on this please?

    Many Thanks


  • Suggested answer
    Bas van de Sande Profile Picture
    Bas van de Sande 4,383 on at
    RE: Accessing oData results and applying them to field

    Hi Lee,

    what comes behind "alert" depends on the oData source you access

    If you don't know how the data looks like, a good approach is to use the javascript debugger of your browser.

    Set a breakpoing on the if(results!=...) line, and see what happens if you run the script on the page.

    Likely, you end up with a syntax like:   alert = results.fieldname;

    I hope this helps you forward

    Bas

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans