从实体主页(网格视图)检索实体属性

Retrieve Entity attributes from the Entity homepage (Grid view)

本文关键字:实体 检索 属性 视图 网格 主页      更新时间:2023-09-26

我已经构建了一个进程,该进程将由功能区中的按钮调用。我已将其添加到表单视图中,没有问题,我希望它也可以从网格视图中工作。

问题是我在实际过程开始之前验证了一些数据。在可视功能区中,我将 SelectedControlSelectedItemIds 作为参数传递,并且仅在仅选择一条记录时启用该按钮。

调用的JS如下所示:

function AutoQualify(dialogId, typeName, recordId, width, heigth) {

    retrieveLeadRecord(recordId);
    var stateCode = getLeadStateCode(recordId)
    if ((stateCode === null) || (stateCode === undefined) || (stateCode === "")) {
        alert("status Code fält kan inte vara tömt");
        return;
    }
    if ((stateCode != 0)) {
        alert("Man kan inte köra Quicksale från ett kvalificerat Lead");
        return;
    }
    var firstName = GetAttributeValue('firstname');
    if ((firstName === null) || (firstName === undefined) || (firstName === "")) {
        alert("Förstanamn fält kan inte vara tömt");
        return;
    }
    var lastName = GetAttributeValue('lastname');
    if ((lastName === null) || (lastName === undefined) || (lastName === "")){
        alert("Efternamn fält kan inte vara tömt");
        return; 
    }
    var companyName = GetAttributeValue('companyname');
    if ((companyName === null) || (companyName === undefined) || (companyName === "")) {
        alert("Företagsnamn fält kan inte vara tömt");
        return;
    }
    var orgNummer = GetAttributeValue('custom_corporateidentificationnumber');
    if ((orgNummer === null) || (orgNummer === undefined) || (orgNummer === "")) {
        alert("Organisationsnummer fält kan inte vara tömt");
        return;
    }
    var leadSourceCode = GetAttributeValue('leadsourcecode');
    if ((leadSourceCode === null) || (leadSourceCode === undefined) || (leadSourceCode === "")) {
        alert("Leadskälla fält kan inte vara tömt");
        return;
    }
    var mailAddress = GetAttributeValue('emailaddress1');
    var telephone = GetAttributeValue('telephone1');
    if (((mailAddress === null) || (mailAddress === undefined) || (mailAddress === "")) && ((telephone === null) || (telephone === undefined) || (telephone === ""))) {
        alert("Man måste ange e-post adress eller telefonnummer");
        return;
    }
    if (confirm("Vill du kvalificera leadet?")) {
        LaunchModalDialogChangeSize(dialogId, typeName, recordId, width, heigth, Xrm.Page.context.getServerUrl() );
    }
}

检索用户记录函数:

function retrieveLeadRecord(Id) {
    var serverUrl = Xrm.Page.context.getServerUrl();
    var GlobalODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
    var select = "/LeadSet?$select=StateCode,StatusCode&$filter=LeadId eq guid'" + Id + "'";
    showMessage("retrieveLead function START");
    var retrieveLeadReq = new XMLHttpRequest();
    retrieveLeadReq.open("GET", GlobalODataPath + select, true);
    retrieveLeadReq.setRequestHeader("Accept", "application/json");
    retrieveLeadReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    alert("3");
    retrieveLeadReq.onreadystatechange = function () {
        retrieveLeadReqCallBack(this);
};
    retrieveLeadReq.send();
    showMessage("retrieveLead function END.");
}

但永远不会通过XMLHttpRequest声明。缺少图书馆吗?

虽然我评论了,但现在我重读了它,你的代码看起来不正确。即使您只在网格中选择 1 行,ID 仍将作为数组出现(通过recordId我想如果您的属性设置正确)。但是您将遇到的问题是您需要同时处理表单和网格。因为表单只会给你一个 ID,而网格视图会传入一个数组(或者可能是逗号分隔的字符串,我不记得是哪个)/

因此,实际上您需要做以下 2 件事中的 1 件事:

  1. 选项 1 在 JavaScript 中检查变量"recordId",看看它是否只是 1 个 id 或它是多个。根据它是数组还是分隔字符串,代码可能会有所不同,所以我没有一个例子

  2. 选项 2 是创建第二个函数,该函数接受 recordId 并通过第一个元素传递到另一个函数。然后,您可以将网格按钮设置为改为调用此函数。函数看起来像这样:

    function AutoQualifyMultiple(dialogId, typeName, recordIds, width, heigth)
    {
      AutoQualify(dialogId, typeName, recordIds[0], width, heigth);
    }

我设法修复了它。在可视功能区编辑器中,我有一个启用规则,该规则仅在仅选择一条记录时才启用该按钮。另一个激活规则,如果调用 activateQuicksaleForLead,则使用 SelectedControlSelectedItemId 一个参数。该按钮需要函数返回 true 才能启用。

function activateQuicksaleForLead(recordId) {
    function myBool() {
        this.value = true;
    }
    var active = new myBool();
    retrieveLeadStatus(recordId, active);
    return active.value;
}

检索线索状态通过对 oData CRM Web 服务进行同步调用来检索值

function retrieveLeadStatus(Id, active) {
    var serverUrl = Xrm.Page.context.getServerUrl();
    var GlobalODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
    var select = "/LeadSet?$filter=LeadId eq guid'" + Id + "'";
    var retrieveLeadReq = new XMLHttpRequest();
    retrieveLeadReq.open("GET", GlobalODataPath + select, false);
    retrieveLeadReq.setRequestHeader("Accept", "application/json");
    retrieveLeadReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    retrieveLeadReq.send(null);
    var records = JSON.parse(retrieveLeadReq.responseText).d;
    var stateCode = records.results[0].StateCode.Value;
    if ((stateCode === null) || (stateCode === undefined) || (stateCode === "")) {
        alert("Det går inte att hitta posten. Kontakta din system admininistrator.");
        activateQuickSaleLead = false;
        return;
    }
    if ((stateCode != 0)) {
        active.value = false;
        return;
    }
    else {
        active.value = true;
        return;
    }
}