Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Unable to Retrieve Entity Value from XRM.WebApi Request

Posted on by 60

I am unable to read a value from an Xrm.WebApi request in my Javascript. I have tested using Executed Code in CRM REST Builder, and results are indeed retrieved.

Below is my code snippet:

Xrm.WebApi.online.retrieveMultipleRecords("percentile", "?$select=maleage").then(
    function success(results) {
        for (var i = 0; i < results.entities.length; i  ) {
            var ccc_maleage = results.entities[i]["maleage"];
        }
    },
    function(error) {
        Xrm.Utility.alertDialog(error.message);
    }
);

When comparing the values in Javascript:

for (index = 0; index < results.entities.length;   index) {

    alert("results.entities.length: "   results.entities.length); //displays 18
    
    var age = results.entities[index].maleage;
    
    alert("age: "   age); //always displayed as "undefined"
    
    if (months == age) 
    {
        //no match due to "undefined" age
    }
}

May I know what have I done wrongly? This issue has been occurring On and Off, and it is very unstable.

  • Suggested answer
    RE: Unable to Retrieve Entity Value from XRM.WebApi Request

    Hello,

    I noticed 2 things in code which maybe /maybe not causing the issue but just sharing with you -

    1. You can try using Xrm.WebApi.retrieveMultipleRecords API and see if it helps. You can explore this article to get more details -  docs.microsoft.com/.../retrievemultiplerecords 

    2. Instead of using Xrm.Utility.alertDialog API, you should use Xrm.Navigation.openAlertDialog as Xrm.Utility.alertDialog API is deprecated. You can find this info here -https://docs.microsoft.com/en-us/power-platform/important-changes-coming#some-client-apis-are-deprecated

  • Daniel Schneider Profile Picture
    Daniel Schneider 170 on at
    RE: Unable to Retrieve Entity Value from XRM.WebApi Request

    Hi,

    make a breakpoint in for loop at first line and expand results.entities. Take a look in index 0 is there a property maleage?

    If no write results.entities[index]["maleage"] and see what you get.

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans