Skip to main content

How to automatically join DingTalk roles

1. Scenario

When applying for new employees, HR usually needs to enter employee information first, then add new employees to the company's organizational structure in the DingTalk management background, and create a new role list, add employees to specific roles. However, when there are a large number of employees, repeated entry will be tedious and easy to make mistakes. So how can we make it easy for employees to enter the job?

We can use the connector to automatically add the pending information of the member to the intelligent personnel when submitting the employee information data, and use the connector to add the employee to a specific role, not only is it convenient and fast, but also it is not easy to make mistakes, so let's take a look at how to achieve it!

2. Implementation steps

2.1 Open platform registration

First, open the platform DingTalkhttps://open-dev.dingtalk.com /#/Register an enterprise application.

Then, create an enterprise internal application named employee role addition ".

After the application is created, switch to permission management-> address book management-> Select All permission information-> batch application.

Finally, switch to the application information page and record the AppKey and AppSecret values. The following connector authentication needs to be used.

2.2 custom connector

Get Role list connector

Access the Get Role list interface in the server API list of the DingTalk open platform, and configure a custom connector according to the documentation.

https://open.dingtalk.com/document/orgapp-server/obtains-a-list-of-enterprise-roles

Visit platform management> connector factory in YIDA, and then create an HTTP connector ".

Fill in the basic information, key points:Select DingTalk open platform authentication 」, click next ".

Enter the information of the Get Role list interface.

Create a verification account, fill in the AppKey and AppSecret above, and save the selection. At the same time, enter the corresponding parameters Request Body. By default, there are 20 requests.

Click the "test" button and the Status is 200 to obtain the corresponding results. The information of the role list includes the id and name fields.The page size can be up to 200.

Increase employee roles in batches

In the server API list of the open platform DingTalkAdd employee roles in batches"Interface, and configure a custom connector according to the document information.

https://open.dingtalk.com/document/orgapp-server/add-role-information-to-employees-in-batches

Configure basic information about custom HTTPS connectors.

Configure execution action information

Finally, enter the role id obtained by the previous "get role list" and your uid in the current organization, enter Request Body, and click the "test" button to view the results.

The last errcode result is 0, indicating that the execution is successful.

We went to the DingTalk OA management background and checked the results in role management. We found that Yan Xin had been added to the IT role Group, indicating that the two connectors were configured and executed successfully.

3. Use in forms or integration automation

It is mainly used in integration automation to construct two parameters, roleIds and userIds. Both parameters are in string format, so it is more suitable to store them in a single-line text box.

3.1 conversion in form

Case 1: add users to a single role

Add a selection component and a single-line text component (employee id) to tick the show employee ID.

The employee id component configures the formula for obtaining the employee id.

You can convert the list of roles obtained by The Get Role list connector to a drop-down radio or radio component.

The role name and role id are option name and option id respectively 」.

Case 2: add users to multiple roles at the same time

Add a select component to hook the multi-select mode and show employee ID. Add a single-line text component of employee id.

Add onChange functions to the employee component.

onChange function code

You can convert the role list obtained by The Get Role list connector to a drop-down check or check component.

The role name and role id are option name and option id respectively 」.

3.2 Use in integrated automation

Create a trigger triggered by a form event.

Select the created event in the form, and then select the custom employee add role connector.

In the role list, select DingTalk role-single choice, select employee id in the employee list, and then save the release.

Submit the form and verify it.

Verification results:

If it is a multi-choice situation.

Background verification results:

The same is true for multiple roles. You need to construct the value of the roleIds field.

4. Debugging method

4.1 view logs

Check whether the connector is running successfully and whether an error has been reported through the integrated automation run log.

4.2 message reminder print field

Add a message notification node, print the values of each field submitted in the form, and check whether the format meets expectations.

View the results of message notifications.

This doc is generated using machine translation. Any discrepancies or differences created in the translation are not binding and have no legal effect for compliance or enforcement purposes.
Copyright © 2024钉钉(中国)信息技术有限公司和/或其关联公司浙ICP备18037475号-4