Skip to main content
Dynamics 365 general forum

Add entity records to list

editSubscribe (0) ShareShare
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 =;
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) {


  • Verified answer
    PabloCRP Profile Picture
    PabloCRP 1,086 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 = [];


    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];


    please consider marking as an answer if it was helpful

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…


Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,045 Super User

Martin Dráb Profile Picture

Martin Dráb 222,570 Super User

nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans