用于检索查找数据的 Dynamics CRM 2011 表单 jscript

发布于 2024-11-29 19:05:29 字数 2681 浏览 2 评论 0原文

我的错误是什么,为什么会出现“预期对象”错误,以及最终如何调试 jScript?

我是 Dynamics CRM 的新手,我想做一个小的自定义,这似乎需要jScript。该实例(版本 2011)主要用于管理客户端支持。

有 2 个具有关系的自定义实体: FundLegalEntity -->子基金

案例(事件)表格链接到 FundLegalEntity 和子基金。
当用户输入子基金时,我希望自动填充 FundLegalEntity(如果为空)。
我的问题是:如何编码

这个很棒的教程的帮助下, 非常有用的oData工具,以及来自用户@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'); 
        }
    });       

} 

我没有更多错误,前两个警报(注释掉)给了我正确的结果。 第三个警报显示“对象对象”,而我期望更新的控件未更新。
有什么提示吗?我想最后一个问题是在 varparentFundLookup = 行中...
我对这些不同的名字有点困惑。
谢谢 !


编辑:

现在几乎可以正常工作:当我修改事件中的子基金时,法人实体会使用正确的法人实体名称进行更新,但文本框有一个奇怪的方面,文本框左侧的图标是也很奇怪。这是最新的代码:

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" 中,但我不知道要在那里放什么。这有什么线索吗?这代表什么?
这是子基金更新且脚本运行后法人实体的屏幕截图

What are my mistakes, why do I get the "object expected" error, and, eventually, how does one debug jScript ?

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.

There are 2 custom entities with relationships: FundLegalEntity --> SubFund

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 ?

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'); 
        }
    });       

} 

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 !


Edit:

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);
    },

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼趣 2024-12-06 19:05:29

您可以使用脚本中的 Rest 端点从组织服务检索数据。这是一个帮助您入门的示例。您还可以查看 SDK 文档,其中有很多有用的信息。

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 库添加为 Web 资源并将其包含在表单中。请参阅 CRM 2011“$ 未定义”

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'); 
        }
    });

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文