您好,所有专家(我很快就会有一天!) 这是一个问题。 我想获取报价实体中相关价格水平(价目表实体)的状态码或状态码。(相关的一个) 我已经在Quote实体(OnLoad)中尝试了JS:
var priceLevelStatusCode=Xrm.Page.getAttribute("pricelevelid").getValue()[0].statuscode;
alert(priceLevelStatusCode );
但是它在警告框中显示了我未定义的内容! 但是当我尝试这个时:
var priceLevelStatusCode=Xrm.Page.getAttribute("pricelevelid").getValue()[0].name;
alert(priceLevelStatusCode );
它为我提供了报价内价格表的正确名称。 问题是什么?如何获取价目表的状态码或状态码?
更新1:
我知道应该致电OData
,所以我这样做了:
function autoAlarm() {
var pricelevelid = Xrm.Page.getAttribute("pricelevelid").getValue()[0].id;
oDataPath = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organizationdata.svc"
var Odata = oDataPath + "/PricelevelSet?$select=name,statecode&$filter=PricelevelId eq guid'" + pricelevelid + "'";
try {
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", Odata);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveReqCallBack(this);
}
retrieveReq.send();
}
catch (err) {
var text = "There was an error on this page.\n\n";
text += "Error description: " + err.message + "\n\n";
text += "Click OK to continue.\n\n";
alert(text);
}
}
function retrieveReqCallBack(retrieveEntityReq) {
var PrefixText = ""
if (retrieveEntityReq.readyState == 4) {
retrieveEntityReq.onreadystatechange = null;
alert(retrieveEntityReq.status);
if (retrieveEntityReq.status == 200) {
var retrievedEntity = JSON.parse(retrieveEntityReq.responseText).d;
alert(retrievedEntity.hasOwnProperty("statuscode"));
alert(retrievedEntity.statuscode);
}
}
}
但是现在它给我错误404(我认为没有找到!)。 我在哪里做错了?
更新2:
我解决了错误号404。
这是因为区分大小写。
现在,当我要检索该值时,它将显示Undefined
。
这是我的新代码:
function autoAlarm() {
var pricelevel = Xrm.Page.getAttribute("pricelevelid").getValue()[0].id;
var pricelevelid = pricelevel.replace("{","").replace("}","");
oDataPath = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc"
var Odata = oDataPath + "/PriceLevelSet?$select=Name,StateCode&$filter=PriceLevelId eq guid'" + pricelevelid + "'";
try {
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", Odata);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveReqCallBack(this);
}
retrieveReq.send();
}
catch (err) {
var text = "There was an error on this page.\n\n";
text += "Error description: " + err.message + "\n\n";
text += "Click OK to continue.\n\n";
alert(text);
}
}
function retrieveReqCallBack(retrieveEntityReq) {
var PrefixText = ""
if (retrieveEntityReq.readyState == 4) {
retrieveEntityReq.onreadystatechange = null;
alert(retrieveEntityReq.status);
if (retrieveEntityReq.status == 200) {
var retrievedEntity = JSON.parse(retrieveEntityReq.responseText).d;
alert(retrievedEntity.hasOwnProperty("StateCode"));
alert(retrievedEntity.StateCode);
}
}
}
首先显示false(代码:alert(retrievedEntity.hasOwnProperty("StatusCode"));
然后显示undefiend
。
当我在浏览器中转到Odata
URL时,会看到关于状态和状态代码的信息:
<d:StateCode m:type="Microsoft.Crm.Sdk.Data.Services.OptionSetValue">
<d:Value m:type="Edm.Int32">0</d:Value>
</d:StateCode>
<d:OrganizationId m:type="Microsoft.Crm.Sdk.Data.Services.EntityReference">
<d:Id m:type="Edm.Guid">f52acfb9-78de-402a-a9c2-8229836f0b7e</d:Id>
<d:LogicalName>organization</d:LogicalName>
<d:Name>xxxxx</d:Name>
</d:OrganizationId>
<d:StatusCode m:type="Microsoft.Crm.Sdk.Data.Services.OptionSetValue">
<d:Value m:type="Edm.Int32">100001</d:Value>
</d:StatusCode>
有人可以帮忙吗?
(已解决)更新3:
最后我可以得到statecode
,这是代码:
function autoAlarm() {
var pricelevel = Xrm.Page.getAttribute("pricelevelid").getValue()[0].id;
var pricelevelid = pricelevel.replace("{","").replace("}","");
oDataPath = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc"
var Odata = oDataPath + "/PriceLevelSet?$select=Name,StateCode&$filter=PriceLevelId eq guid'" + pricelevelid + "'";
try {
var retrieveReq = new XMLHttpRequest();
retrieveReq.open("GET", Odata);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () {
retrieveReqCallBack(this);
}
retrieveReq.send();
}
catch (err) {
var text = "There was an error on this page.\n\n";
text += "Error description: " + err.message + "\n\n";
text += "Click OK to continue.\n\n";
alert(text);
}
}
function retrieveReqCallBack(retrieveEntityReq) {
var PrefixText = ""
if (retrieveEntityReq.readyState == 4) {
retrieveEntityReq.onreadystatechange = null;
if (retrieveEntityReq.status == 200) {
var retrievedEntity = JSON.parse(retrieveEntityReq.responseText).d;
var priceLevelStateCode=retrievedEntity.results[0].StateCode.Value;
alert(priceLevelStateCode);
}
}
}
我的错误是得到Json Array
,真正的方法是:
var priceLevelStateCode=retrievedEntity.results[0].StateCode.Value;
谢谢大家。
答案 0 :(得分:0)
价格级别是对报价的查找,您可以使用Xrm.Page.getAttribute("pricelevelid").getValue()[0]
获取该相关实体记录的ID和名称(显示文本)。对于任何其他属性(例如状态码),您必须进行Web api调用,才能使用ID密钥从数据库中获取它。
更新:
您可以使用与2011年兼容的CRM REST Builder来构建查询,可以在CRM表格js库中使用测试和准确的代码段。在Dev CRM实例中下载并导入此托管解决方案,并立即生成查询。
OrganizationData.svc
并通过包装在XMLHttpRequest
中来检索必要的属性。 Read more
示例:
var pricelevelid = Xrm.Page.getAttribute("pricelevelid").getValue()[0].id;
var Odata = oDataPath + "/PriceLevelSet?$select=name,statecode&$filter=PriceLevelId eq guid'" + pricelevelid + "'";
答案 1 :(得分:0)
查找控件包含目标实体的ID
和Name
。
在您的情况下,查找控件是pricelevelid
控件
如果您想从相关的价格水平记录中获取更多信息,则需要检索特定记录。
要在CRM 365中做到这一点
以下是有关如何使用此方法的MSDN Article的链接,但基本上您可以提供:
pricelevel
)应该是这样的:
var pricelevelid = Xrm.Page.getAttribute("pricelevelid").getValue()[0].id;
Xrm.WebApi.retrieveRecord(
"pricelevel",
pricelevelid,
"?$select=name,statuscode",
function(record) { alert (record.name); },
function(err) { alert(err); }
);