Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Add entity records to list

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

    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

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

Product updates

Dynamics 365 release plans