web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans