问题描述
我的错误是什么,为什么会出现期望的对象错误,以及最终如何调试jScript?
我是Dynamics CRM的新手,我想进行一些小型定制,这似乎需要jScript。该实例(2011版)主要用于管理客户端支持。
I am new to Dynamics CRM and I would like to do a small customisation, which seem to require jScript. The instance (version 2011) is used mostly to manage client support.
有2个具有关系的自定义实体:FundLegalEntity-> SubFund
There are 2 custom entities with relationships: FundLegalEntity --> SubFund
案例(事件)形式为
当用户输入SubFund时,我希望自动填写FundLegalEntity(如果为空)。
我的问题是:怎么办我写那个?
The Case (Incident) form is linked to the FundLegalEntity and the SubFund.
When user enters a SubFund I would like to have the FundLegalEntity filled automatically (if empty).
My question was: how do I code that ?
借助,以及,以及非常有用的帮助(下面)来自用户@dub,这是我的最新代码:
With the help of this great tutorial, and the very usefull oData Tool, and great help (below) from user @dub, here is my latest code:
function recalcParent()
{
var lookupValue = Xrm.Page.getAttribute("new_subfundid").getValue();
var subFundId= lookupValue[0].id;
// alert(subFundId);
var request = Xrm.Page.context.getServerUrl() +
"/xrmServices/2011/OrganizationData.svc/new_subfundSet?" +
"$select=new_LegalEntityId&" +
"$filter=new_subfundId eq guid'"+ subFundId+ "'";
// alert(request);
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: request,
async: false,
beforeSend:
function (XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success:
function (data, textStatus, XmlHttpRequest)
{
var result = data.d.results[0];
alert(result);
var parentFundLookup = [{ entityType : "new_fund", id : result.LegalEntityId, name : result.FundLegalEntity}];
// Set the value of the parent fund lookup
},
error:
function (XmlHttpRequest, textStatus, errorThrown)
{
alert('Failed');
}
});
}
我没有更多错误了,前2个提醒(注释出来)给我正确的结果。
第三个警报显示对象对象,并且我希望更新的控件未更新。
请提示吗?我想最后一个问题是在 var parentFundLookup =
行中。
我对所有这些不同的名称感到有些困惑。 b $ b谢谢!
I have no more errors, the first 2 alerts (commente out) are giving me correct results.THe 3rd alert displays "object Object", and the control I expect to update is not updated.
Any hint please ? I suppose the last problem is in the var parentFundLookup =
line...
I am a bit confused by all these different names.
Thanks !
现在几乎可以使用了:当我修改事件中的子基金,法人实体将使用正确的法人实体名称进行更新,但是文本框具有一个奇怪的方面,并且文本框左侧的图标也很奇怪。这是最新的代码:
It's nearly working now: when I modify the sub-fund in the Incident, the Legal Entity gets updated with the correct legal entity name, but the text box has a strange aspect, and the icon at the left of the text box is strange as well. Here is the latest bit of code:
success:
function (data, textStatus, XmlHttpRequest)
{
var result = data.d.results[0];
//alert(result.new_LegalEntityId.Name);
var parentFundLookup = [{ entityType : "new_LegalEntity", id : result.new_LegalEntityId.Id, name : result.new_LegalEntityId.Name}];
Xrm.Page.getAttribute("new_fundlegalentityid").setValue(parentFundLookup);
},
我怀疑问题出在 entityType : new_LegalEntity
,但是我不知道该放什么。有什么线索吗?这代表什么?
I suspect that the problem lies in the entityType : "new_LegalEntity"
, but I don't know what to put in there. Any clue on this ? What does that represent ?
Here is a screenshot of the Legal Entity after the Sub-Fund is updated and the script has run.
推荐答案
您可以使用脚本中的Rest端点从组织服务中检索数据。这是一个入门的示例。您也可以查看SDK文档,那里有很多有用的信息。
You can use the Rest endpoint from your script to retrieve data from the organization service. Here's an example to get you started. You can also look at the SDK documentation there's a lot of useful information there.
var subfundid; // get the id from the lookup
var request =
Xrm.Page.context.getServerUrl() +
"/XRMServices/2011/OrganizationData.svc/new_subfundSet?" +
"$select=ParentId&" +
"$top=1&" +
"$filter=new_subfundId eq guid'"+ subfundid + "'";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: request,
async: false,
beforeSend:
function (XMLHttpRequest)
{
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success:
function (data, textStatus, XmlHttpRequest)
{
var result = data.d.results[0];
var parentFundLookup = [{ entityType : "new_fund", id : result.ParentId, name : result.FundName}];
// Set the value of the parent fund lookup
},
error:
function (XmlHttpRequest, textStatus, errorThrown)
{
alert('Failed');
}
});
由于此代码使用了JQuery,因此您需要将JQuery库添加为网络资源并包含它以您的形式。请参见
Since this code uses JQuery, you'll need to add the JQuery library as a web resource and include it in your form. See CRM 2011 "$ is undefined"
这篇关于Dynamics CRM 2011表单JScript检索查找数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!