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); } );