简体   繁体   English

Dynamics 365 CRM:根据来自不同实体的状态在表单中显示/隐藏

[英]Dynamics 365 CRM: Show/Hide in forms based on Status from different Entity

I am working in CRM and have created two new Qualify statuses for a Win.我在 CRM 工作,并为 Win 创建了两个新的 Qualify 状态。 The first status is "Appointment Made" and the second is "Hardware Quoted".第一个状态是“Appointment Made”,第二个状态是“Hardware Quoted”。 When you choose one of these and qualify the lead, the status of the lead is then changed to the option you selected.当您选择其中之一并限定潜在客户时,潜在客户的状态将更改为您选择的选项。

In the Opportunity forms, I have a tab with a section and fields which include fields to be used if "Appointment Made" was selected and same for "Hardware Quoted".在商机表单中,我有一个选项卡,其中包含一个部分和字段,其中包括在选择“Appointment Made”和“Hardware Quoted”相同的情况下要使用的字段。

What I need help with is the JavaScript code which I can hopefully insert into an event on the form/field properties to hide the other tab, when one was selected originally.我需要帮助的是 JavaScript 代码,当最初选择一个选项卡时,我希望可以将其插入到表单/字段属性上的事件中以隐藏另一个选项卡。

Here is the rough code I have been working on:这是我一直在处理的粗略代码:

function showHideTabAndSection() {
    var statuscode = $("#statuscode").val();
    var showTab = false;
    var showSection = false;

    if (statuscode = 100000004) {
        showTab = true;
        showSection = true;
    }
    Xrm.Page.ui.tabs.get("TestTab1").setVisible(showTab);
    Xrm.Page.ui.tabs.get("TestTab1").sections.get("TestSection1").setVisible(showSection);
}

Can anyone help?任何人都可以帮忙吗? Thanks.谢谢。

make sure that "statuscode" in the same form with "TestTab1" or in another Form.确保“statuscode”与“TestTab1”或其他表单的表单相同。 if They were in different Forms You must retrieve it's value.如果它们采用不同的形式,您必须检索它的值。

See That: JavaScript – OData Query请参阅: JavaScript – OData 查询

In opportunity form load, get the originatingleadid field value from current opportunity record & use it to retrieve the statuscode for controlling the tab/section visibility.在机会的形式负载,获得originatingleadid从目前的机会记录字段值和使用它来检索statuscode控制选项卡/节的知名度。

Recommend you to use CRM REST Builder & I generated this below code from there.建议您使用CRM REST Builder & 我从那里生成了以下代码。 If you are in V9 you can use web api to do the same.如果您使用的是 V9,您可以使用 web api来做同样的事情。

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/leads(<<originatingleadid of opportunity>>)?$select=statecode,statuscode", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var result = JSON.parse(this.response);
            var statecode = result["statecode"];
            var statecode_formatted = result["statecode@OData.Community.Display.V1.FormattedValue"];
            var statuscode = result["statuscode"];
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

Lets say, Appointment Made has value 1, Hardware Quoted has value 2.可以说, Appointment Made 的值为 1, Hardware Quoted 的值为 2。

function showHideTabAndSection() {
    var statuscode = Xrm.Page.getAttribute("statuscode").getValue();
    switch (statuscode) {
        case 1:
            Xrm.Page.ui.tabs.get("appointMadeTab").setVisible(true);
            Xrm.Page.ui.tabs.get("hardwareQuotedTab").setVisible(false);
            break;
        case 2:
            Xrm.Page.ui.tabs.get("appointMadeTab").setVisible(false);
            Xrm.Page.ui.tabs.get("hardwareQuotedTab").setVisible(true);
            break;
    }
}

Hope it helps.希望能帮助到你。

Bro I'm sorry to inform you that you just made a simple typo兄弟 我很抱歉地通知你,你刚刚犯了一个简单的错字

if (statuscode = 100000004) {
   

As you see, the operator should be '==' not '='如您所见,运算符应该是 '==' 而不是 '='

I guess, that's why your code doesnt work.我想,这就是为什么你的代码不起作用。

To find problems like this in runtime, always add this line to your code debugger;要在运行时发现此类问题,请始终将此行添加到您的代码调试器中;

this will stop code execution and debugs the code if you have Chrome's inspect element window open.如果您打开 Chrome 的检查元素窗口,这将停止代码执行并调试代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM