web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    crm development Profile Picture
    870 on at

    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

  • rthompson Profile Picture
    1,532 on at

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

  • Verified answer
    crm development Profile Picture
    870 on at

    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

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans