Dynamics 365 field is automatically calculated using real number field encoded packets generated automatically workflow plus automated serial number field value

I am a Microsoft Dynamics 365 & Power Platform aspects engineer Rayong, Microsoft Most Valuable Professional is the July 2015 to June 2018 for three consecutive years Dynamics CRM / Business Solutions aspects (Microsoft MVP), I welcome the attention of the public micro-channel number MSFTDynamics365erLuoYong, reply or 20,191,105 376 may facilitate access to this article, but you can get the latest information I Bowen issued in the first room, follow me!

I suppose a scene here, test custom entities need an auto number field, the value of address1_country create this record number of people, a business sector plus a 6-digit serial number, such as ZH-000001.

The plugin must use to write code to achieve it? Necessarily, with an automatic type of field numbers, plus a calculated field can be configured in real time out of the workflow.

First I need to TestEntity create a field test Autonumber format for this entity to introduce this field, please refer to my blog Auto Numbering property Dynamics 365 Customer Engagement V9.X newly introduced presentation , as shown.

 

 

 

Then I need to display address1_country field values ​​belong business user in the user, how to do? To do with the calculated field. The user (SystemUser) adding a calculated field following entities:

 

 

 

Calculated as can be seen the value field address1_country business unit the user belongs.

 

 

The increase in this new field displays to the user entity form release you can see the effect. But you can not change the default field values ​​root business unit, as a parent can not choose their business, saving time will complain You must provide a value for Parent Business., As follows.

 

 

那怎么办?参考我的博文:不借助工具在浏览器中通过Web API执行Dynamics 365操作(Action)实例 ,我是用如下的JS代码来设置根业务部门这个字段的值。

var clientURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest()
req.open("PATCH", encodeURI(clientURL + "/api/data/v9.1/businessunits(3B4C4300-9AD7-E911-AA0E-000D3AA3715F)"), true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
        req.onreadystatechange = null;
        if (this.status == 204) {
            Xrm.Utility.alertDialog("记录修改成功!");
        }
        else {
            var error = JSON.parse(this.response).error;
            Xrm.Utility.alertDialog("修改记录出错." + error.message);
        }
    }
};
var requestMsg = {};
requestMsg["address1_country"] = "ZH";
req.send(JSON.stringify(requestMsg));

 

可以看到我更新成功了。

 

 然后我需要建立一个实时工作流,实时工作流就是创建的流程种类选择 工作流(Workflow),然后 Run this workflow in the background (recommended) 这个选项不要选中。

 

 

该实时工作流触发的实际选择 After Record is created,一般我选择Execute as the owner of the workflow,以免实时工作流运行碰到权限问题。

 

 

 添加一个步骤来设置当前实体这个自定义编号字段的值,字段值设置为两个字段值的组合,分别如下:

 

 

 

 

这两个字段值组合起来的值如下:

 

 

 然后我去测试下,我新建一条记录,保存,可以看到生成了我想要的自定义编号格式。

 

Guess you like

Origin www.cnblogs.com/luoyong0201/p/Dynamics_365_Calculate_Field_Real-time_Workflow_AutoNumber.html