Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

SDK.REST.retrieveMultipleRecords $expand not sure what I am doing wrong

(0) ShareShare
ReportReport
Posted on by 1,532

Hi

I am trying to use the "$expand" to retrieve two columns from a different entity.  Can't see what I am doing wrong.

The primary entity is "new_casedatasheettemplatemodel".

The secondary entity is "new_casemodel".

Here's my error message:

8508.ErrorMessage.JPG

Here's my code:

function buildCaseModelSDK() {

    var caseId = $("#form_caseid").val();
    var caseDataSheetTemplateId = $("#form_casedatasheettemplateid").val();

    if (caseId != null && caseDataSheetTemplateId != null) {
        var iselect = "?$select=new_CaseId";

        iselect += "&$expand=new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId($select=new_ModelId,new_SampleGroupId)"

        var ifilter = "&$filter=(new_CaseId/Id eq guid'" + caseId.replace(/{/g, "").replace(/}/g, "") + "'";
        ifilter += " and new_CaseDataSheetTemplateId/Id eq guid'" + caseDataSheetTemplateId.replace(/{/g, "").replace(/}/g, "") + "'";
        ifilter += ")";

        var iorderby = "&$orderby=new_name";

        var options = iselect + ifilter + iorderby;

        SDK.REST.retrieveMultipleRecords("new_casedatasheettemplatemodel", options, buildCaseModelCallBack, function (error) { alert(error.message + "[" + options); }, buildCaseModelCompleted);
    }
}

///---------------
function buildCaseModelCallBack(caseModels) {
    var models = caseModels;
}
function buildCaseModelCompleted() {

}

*This post is locked for comments

  • rthompson Profile Picture
    1,532 on at
    RE: SDK.REST.retrieveMultipleRecords $expand not sure what I am doing wrong

    Thanks very much for your help.  That did the job.

  • Verified answer
    crm development Profile Picture
    870 on at
    RE: SDK.REST.retrieveMultipleRecords $expand not sure what I am doing wrong

    Great. I will suggest you to use "CRM REST Builder" to verify your query.

    For your question about selecting certain fields ( If I am assuming correctly they are new_ModelId, new_SampleGroupId) from the second entity, try below code

    var iselect = "?$select=new_CaseId";

    iselect += ",new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId/new_ModelId,new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId/new_SampleGroupId";

    iselect += "&$expand=new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId";

    var ifilter = "&$filter=(new_CaseId/Id eq guid'" + caseId.replace(/{/g, "").replace(/}/g, "") + "'";

    ifilter += " and new_CaseDataSheetTemplateId/Id eq guid'" + caseDataSheetTemplateId.replace(/{/g, "").replace(/}/g, "") + "'";

    ifilter += ")";

    var iorderby = "&$orderby=new_name";

    var options = iselect + ifilter + iorderby;

    SDK.REST.retrieveMultipleRecords("new_casedatasheettemplatemodel", options, buildCaseModelCallBack, function (error) { alert(error.message + "[" + options); }, buildCaseModelCompleted);

    // var new_ModelIdValue = results[i].new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId.new_ModelId;

    // var new_SampleGroupIdValue = results[i].new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId.new_SampleGroupId;

  • rthompson Profile Picture
    1,532 on at
    RE: SDK.REST.retrieveMultipleRecords $expand not sure what I am doing wrong

    Hi,

    It's working now. I removed the extra $select.

    How do I only select certain fields from the second entity.

    iselect += "&$expand=new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId($select=new_ModelId,new_SampleGroupId)"

    var iselect = "?$select=new_CaseId";
    iselect += ",new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId";
    iselect += "&$expand=new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId";
     
    var ifilter = "&$filter=(new_CaseId/Id eq guid'" + caseId.replace(/{/g, "").replace(/}/g, "") + "'";
    ifilter += " and new_CaseDataSheetTemplateId/Id eq guid'" + caseDataSheetTemplateId.replace(/{/g, "").replace(/}/g, "") + "'";
    ifilter += ")";
     
    var iorderby = "&$orderby=new_name";
     
    var options = iselect + ifilter + iorderby;
     
    SDK.REST.retrieveMultipleRecords("new_casedatasheettemplatemodel", options, buildCaseModelCallBack, function (error) { alert(error.message + "[" + options); }, buildCaseModelCompleted);
    

  • Suggested answer
    crm development Profile Picture
    870 on at
    RE: SDK.REST.retrieveMultipleRecords $expand not sure what I am doing wrong

    Hi, try to add missing semicolon in line and check.  iselect += "&$expand=new_new_casemodel_new_casedatasheettemplatemodel_CaseModelId($select=new_ModelId,new_SampleGroupId)";

    Thanks,

    Anand

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans