【发布时间】:2013-07-31 21:41:45
【问题描述】:
我的错误是什么,为什么会出现“预期对象”错误,以及最终如何调试 jScript?
我是 Dynamics CRM 的新手,我想做一个小的定制,这似乎需要 jScript。该实例(2011 版)主要用于管理客户端支持。
有 2 个具有关系的自定义实体:FundLegalEntity --> SubFund
案例(事件)表单与 FundLegalEntity 和 SubFund 相关联。
当用户输入子基金时,我希望 FundLegalEntity 自动填充(如果为空)。
我的问题是:我该如何编写代码?
在this great tutorial 和the very usefull oData Tool 的帮助下,以及来自用户@dub 的大力帮助(下),这是我最新的代码:
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 个警报(注释掉)给了我正确的结果。
第三个警报显示“object Object”,我希望更新的控件没有更新。
请问有什么提示吗?我想最后一个问题是在var parentFundLookup = 行...
我对所有这些不同的名称有点困惑。
谢谢 !
编辑:
现在几乎可以工作了:当我修改事件中的子基金时,法人实体会更新为正确的法人实体名称,但文本框有一个奇怪的方面,并且文本框左侧的图标也很奇怪。这是最新的代码:
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",但我不知道该放在那里。对此有任何线索吗?这代表什么?
在子基金更新和脚本运行后法律实体的Here is a screenshot。
【问题讨论】:
-
您是否尝试在 Success 函数的末尾更新字段的值?像 Xrm.Page.getAttribute("new_subfundid").setValue(parentFundLookup);
-
不,我没有意识到我必须更换那部分。我马上试试。与此同时,我发现
alert(result.new_LegalEntityId.Name);给了我法人实体的名称,所以我猜我现在走在了正确的轨道上。我觉得这里有点愚蠢,因为这对我来说是一个全新的领域。我对 VBA 和数据库非常了解,但从未使用过任何 JavaScript,也从未调用过 Web 服务。 -
@dub:快完成了,见编辑。谢谢!!
-
你说文本框有一个奇怪的方面。您可以添加屏幕截图或进一步描述问题吗?
-
啊,我明白了。 EntityType 必须是小写的,所以它是 entityType : "new_legalentity"。
标签: dynamics-crm dynamics-crm-2011