简体   繁体   中英

dynamics crm using odata to retrieve a guid from "type: Microsoft.Crm.Sdk.Data.Services.EntityReference"

I have three entities -- 1."Registration" 2."Event" 3."Event Category"

On save of a registration record, I would like to use the guid of the "event" chosen to retrieve the guid of the associated "event category." I believe my trouble retrieving the "event category" guid is because the event category lookup is an EntityReference. I am unsure how to build my odata query to retrieve just the guid of event category.

My code to build the odata URL is as follows:

function getAssociatedEventId () {
var eventId = getEventId ();
retrieveMultiple("new_eventclassSet", "?$select=new_EventCategoryId&$expand=new_new_eventcategory_new_eventclass/new_eventcategoryId&$filter=new_eventclassId eq (guid'" + eventId + "')", findEventQuestions, null, null);
}

function retrieveMultiple(odataSetName, filter, successCallback, errorCallback, _executionObj) {

var serverUrl = Xrm.Page.context.getClientUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName;
if (filter) {
odataUri += filter;
}

First I get the event id through a javascript function in a web resource, and then I'd hope to use that to retrieve the id of the event category associated with the event. When my code runs, it calls the successCallback function, but the data returns "undefined." I believe this is because the data response I get using the URL I've built returns an entity reference. I'm unsure how to build the URL to pin point the Id. I've included a picture of the "response" tab from the developer's console. Hopefully that helps. Thanks very much for any input.

Data Response from Developer's Console

Return of an EntityReference is normal and expected. Just extract the Id , eg EntityReference.Id , that is the Guid of your record.

If the OData service is of protocol version V4, the correct query URL should be:

$filter=new_eventclassId/Id eq 4c2c1c1e-1838-42ca-b730-399816de85f8

Note the absence of single quotes around Guid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM