Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Retrieve Value from array using js.

Posted on by 595

i have a requirement that i'm caling API from flow. From that I'm passing response back to js. That result I'm storing in ja variable.

Now I'm able to get complete result. but while I'm trying to extract particular value from result getting undefined.

Please refer screen shot attached there I'm showing result array in alert.

Screenshot-_2800_156_2900_.png

var result = this.response;
alert("" + result);
var vendor=result["Vendor"];
alert(vendor); 

code snippet.

Please help me to achieve this.

  • Verified answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,319 on at
    RE: Retrieve Value from array using js.

    Hi,

    Thank you for your query.

    I believe the response is in JSON (not an array).

    You need to pars it as JSON using JSON.parse function.

    Here is the sample code for your reference:

    var responseText = '{"Entry_Sheet":1234,"Vendor":"000011"}';
    
    var jsonObj = JSON.parse(responseText);
    
    console.log(jsonObj.Vendor);

    An if the response is a JSON Array (starts with [), look at following example:

    var responseText = '[{"Entry_Sheet":1234,"Vendor":"000011"}]';
    
    var jsonObj = JSON.parse(responseText);
    
    // Read the object using array index
    console.log(jsonObj[0].Vendor);

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans