通过GUID获取实体名称,尽管当前加载了哪种形式以在XrmServiceToolkit.Soap.setState()中使用

问题描述 投票:0回答:1

我被卡在XrmServiceToolkit.Soap.setState()功能上。

先决条件我正在研究MS CRM。我的任务之一是激活和停用记录(这次是本地“联系人”记录)。我决定以以下方式(根据其他任务)构建我的解决方案:

  1. 在我的自定义实体形式的OnLoad事件上,我使用XrmServiceToolkit(任务条件)创建了一个新联系人,然后更新了新创建的联系人中的一个字段。实际上,在生产中在此事件上创建某些东西没有任何意义,但是尽管如此,这样做只是为了我的方便:
function Practice3()
{
    let entityToUpdate = CreateRecordWithToolkit("VP_Created by","Xrm Service Toolkit","4F52999B-0E63-EA11-8125-00155D06F203");
    alert("Switching to new record!");
    Xrm.Utility.openEntityForm("contact", entityToUpdate);
    UpdateFieldsWithXrmServiceToolkit(entityToUpdate);
    DeactivateAndActivateContact(entityToUpdate);
}

// I don't post the CreateRecordWithToolkit(fname, lname, accountId) and UpdateFieldsWithXrmServiceToolkit(targetEntity) functions 'cos all is Ok there
// and entityToUpdate GUID is passed properly
  1. 在创建和发布更新之间,我发送命令以加载该新创建的表单。它并没有立即激活它,但是更新已正确插入。
  2. 然后,我将相同的GUID传递给我的下一个函数DeactivateAndActivateContact(targetEntity),在这里我卡住了。

问题谁能解释或提示如何使用XrmServiceToolkit.Soap.setState()功能?我无法获取“ entityName”参数-这是什么?拥有实体的GUID如何获得它?我试图像这样使用它:

function  DeactivateAndActivateContact(targetEntity)
{
    let entityName = GetObjectAttribute(targetEntity, "contact", "name");
    XrmServiceToolkit.Soap.setState(entityName,targetEntity, "0", "0",false);
    Xrm.Page.data.refresh(true).then(null, null);
}

但出现未定义的错误。

是否有任何方法可以通过GUID获得entityName?因为我正在获取当前表格的名称。进入此行时引发错误:

XrmServiceToolkit.Soap.setState(entityName,targetEntity, "0", "0",false);
javascript dynamics-crm-365 xrmservicetoolkit
1个回答
0
投票

要在此处停用联系人,下面的代码,

注意Rest API call is Asynchronous,您将必须使用execution context and formcontext in Dynamics

此外,您还可以使用Rest API更改其他SOAP调用。请参阅CRM Rest Builder,使用它可以轻松建立呼叫。

var entity = {};
entity.statuscode = 2;
entity.statecode = 1;

    Xrm.WebApi.online.updateRecord("contact", "4A342F12-D248-E211-8669-005056922461", entity).then(
        function success(result) {
            var updatedEntityId = result.id;
formContext.data.refresh(yes).then(successCallback, errorCallback);
        },
        function(error) {
            Xrm.Utility.alertDialog(error.message);
        }
    );
© www.soinside.com 2019 - 2024. All rights reserved.