Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Add entity records to list

(0) ShareShare
ReportReport
Posted on by 355


I used RetrieveMultiple to retrieve records of entity B and in the successCallBack function I want to cycle results to add them to a variable which represents the list of these records, but I'm not sure that it's a correct approach and If I should better use more specific classes or methods to reach my goal and keep track of records.

General scenario: I have my Javascript function in the form of entity E, which is associated with Entity B.
I need to retrieve all records of Entity A associated with the records of B which are linked to this E.

So here I'm retrieving the B records which are linked to this E, and storing them into a variable which will be used in the retrieveMultiple of records A.

Here is my code:

var recordsB;
var formContext = executionContext.getFormContext();
var targetId = formContext.data.entity.getId();
var recordsA;

// retrieve records B associated with this record E:
        Xrm.WebApi.retrieveMultipleRecords("entityB", "?$select=recordB_Id, recordA_id,&$filter=entityE_Id eq"   targetId).then(

            function success(result) {
                 for (var i = 0; i < result.entities.length; i  ) {
//                    recordsB.push(result.entities[i]);
//                }
            },
            function (error) {
                window.alert(error.message);
            }

        );

  • Verified answer
    PabloCRP Profile Picture
    1,088 on at
    RE: Add entity records to list

    Hi, Joel

    you are doing well, here are some thoughts

    1.- Initialize your arrays

    var recordsB = [];
    var recordsA = [];

    2.-

    a.- As you are filtering for a LookUp you must use _lookupname_value format and let a gap between eq and you string concatenation.

    b.- If you need for the GUID of the record its by default entitynameid (there are some exceptions called activities)

    So your filter should be  like assuming you are in entity entityB "?$select=entityBid,_recordAid_value&$filter=_entityE_Id_value eq " targetId

    3.- Cosider that your are working with promises when you are using Xrm.WebApi.retrieveMultipleRecords so success callback will rise at some point in your application.

    4.- Your iteration through result it's good, you are getting all the object but you could just get what you really need and also what you queried

    entityBid and _recordAid_value

    function success(result) {
     var n = result.entities.length;
         for (var i = 0; i < n; i  ) {
            var entity = result.entities[i];
            console.log(entity);
            recordsB.push(entity["entityBid"]);
            if(entity["_recordAid_value"]!==null)
                recordsA.push(entity["_recordAid_value"]);
        }
    }

    regards.

    please consider marking as an answer if it was helpful

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,259 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,988 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans