在子网格表格的加载上获取父属性

时间:2015-10-23 06:25:54

标签: javascript dynamics-crm dynamics-crm-2013 dynamics-crm-online

我有一个实体A的表单,上面有实体B的子网格。子网格(实体B)的表单包含一个选项集,我的要求是根据实体A的属性值限制可以在实体B表单上选择的值。如何获取实体A属性使用JavaScript的实体B表单上的值?

2 个答案:

答案 0 :(得分:2)

您可以查询OData endpoint。在此示例中,我假设处于联系人表单并检索父帐户的关系类型属性。

var accountId = Xrm.Page.getAttribute('parentaccountid').getValue()[0].id;
var url = Xrm.Page.context.getClientUrl();

// OData url. Note that you have to use Schema Names (it's case-sensitive)
url = url + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'"+accountId+"')?$select=CustomerTypeCode";

var req = new XMLHttpRequest();
req.open('GET', url, false); // synchronous call, to keep code short
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.send(null);
var retrievedData = JSON.parse(req.responseText);

// accountData.CustomerTypeCode.Value now contains the numerical value of the optionset

答案 1 :(得分:0)

我使用了SDK.REST.retrieveRecord函数。我们可以从实体B上的查找字段获取父记录ID(这里是实体A)(实体A与实体B具有1:N的关系)并使用上面的REST函数检索所有相关记录。