[英]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"我有三个实体——1.“注册”2.“事件”3.“事件类别”
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."在保存注册记录时,我想使用选择的“事件”的 guid 来检索关联的“事件类别”的 guid。 I believe my trouble retrieving the "event category" guid is because the event category lookup is an EntityReference.我相信我检索“事件类别”guid 的麻烦是因为事件类别查找是一个 EntityReference。 I am unsure how to build my odata query to retrieve just the guid of event category.我不确定如何构建我的 odata 查询以仅检索事件类别的 guid。
My code to build the odata URL is as follows:我构建 odata URL 的代码如下:
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.首先,我通过 Web 资源中的 javascript 函数获取事件 ID,然后我希望使用它来检索与事件关联的事件类别的 ID。 When my code runs, it calls the successCallback function, but the data returns "undefined."当我的代码运行时,它调用了 successCallback 函数,但数据返回“未定义”。 I believe this is because the data response I get using the URL I've built returns an entity reference.我相信这是因为我使用我构建的 URL 获得的数据响应返回了一个实体引用。 I'm unsure how to build the URL to pin point the Id.我不确定如何构建 URL 来确定 ID。 I've included a picture of the "response" tab from the developer's console.我已经包含了来自开发人员控制台的“响应”选项卡的图片。 Hopefully that helps.希望这有帮助。 Thanks very much for any input.非常感谢您的任何意见。
Return of an EntityReference
is normal and expected. EntityReference
返回是正常的且符合预期。 Just extract the Id
, eg EntityReference.Id
, that is the Guid
of your record.只需提取Id
,例如EntityReference.Id
,即您的记录的Guid
。
If the OData service is of protocol version V4, the correct query URL should be:如果 OData 服务的协议版本为 V4,则正确的查询 URL 应为:
$filter=new_eventclassId/Id eq 4c2c1c1e-1838-42ca-b730-399816de85f8
Note the absence of single quotes around Guid.请注意 Guid 周围没有单引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.