How to Assign User's Manager
Most of the incidents that occur in daily work of employees will be one way or another related to their managers. Let's create an assignment policy and set up the request route to assign at a certain stage manager of the user who submitted the request.
Assignment policy is a set of rules for assignment a responsible person.
Model is a set of fields that describe an object. Each object has its own set of fields and, accordingly, records.
Assignment policy allows you to select required user based on the model and use this data for assigning a responsible person.
Let's Configure A New Assignment Policy
The assignment policy settings are located on the Rules page. Click Rules from the left menu and select Assignment policies.
When creating an assignment policy, we have no way to immediately select the manager of the person who submitted the request. To create a policy that links to different fields of different models, you can use several related policies. This way you can get the required record step by step and return its value to the original policy.
Let's divide the creation of this assignment policy on stages and create the necessary related policies one by one.
- We need to apply the assignment policy to the user who created the request. So we creating the policy based on the Request model and selecting the field of the user who created this request - Created by (request.request). This policy will call another related policy.
- The second related policy will be created based on the Users model. Here, we are able to select the user's employee to later identify his manager. Select the Related employees (res.users) field. This policy will call the next one.
- Next policy will be created based on the Employee model. Here we will define user employee's manager - the Manager (hr.employee) field. Now we need to create another policy that will select the user that is in the manager field. Let's create another related policy.
- The final assignment policy will also be created based on the Employee model. The rule type of this policy is User field and it selects the user that is written in the selected field - User (hr.employee). Since the previous policy that triggering this one applies to the manager field, we will thus get the user who is the manager.
For better understanding we can start creating the required assignment policy from the end.
To begin, we will create the assignment policy that will choose the user from the selected field of the Employee model.
On the assignment policies page, click Create to create a new policy.
On the form that opens, do the following:
- Enter the policy name.
- Select the model Employee.
- To create assignment policy rules, click Rules. This will save the created policy.
- On the rules page, click Create to create a new rule and fill out the form.
- In the Type field, select User field.
- In the Assign User Field field, select User (hr.employee).
- Save the rule by clicking Save.
Now let's create the policy that will get the manager field from the Employee model.
- On the policies page, click Create.
- Enter the policy name, select the Employee model.
- Click Rules to create an assignment policy rule.
- Click Create to create the rule.
- Enter the rule name.
- Select the type Related policy.
- In the Assign Related Policy Field, select Manager (hr.employee).
- In the Assign Related Policy field, select the previously created policy (in our case - User - employee).
- Save the rule.
Now we will create an assignment policy in which we can select an employee whose manager we chose.
- On the policies page, click Create.
- Enter the policy name, select the Users model.
- Click Rules to create an assignment policy rule.
- Click Create to create a rule.
- Enter the rule name.
- Select the type Related policy.
- In the Assign Related Policy Field, select Related employees (res.users).
- In the Assign Related Policy field select the previously created policy (in our case - Employee manager).
- Because there may be several employees, you need to specify which entry from the field will be selected. To do this, in the Choice type field, select First (the first entry in this field will be selected).
- Save the rule.
Finally, we can create an assignment policy that will select the user who created the request. This policy will be created based on the Request model.
- On the policies page, click Create.
- Enter the policy name, select the Request model.
- Click Rules to create an assignment policy rule.
- Click Create to create a rule.
- On the rule form, enter the rule name.
- Select the type - Related policy.
- In the Assign Related Policy Field, select Created by (request.request).
- In the Assign Related Policy field select the previously created policy (in our case - User's manager).
- Save the rule.
Test the Created Policy
Note. To test this policy, the HR application need to be installed and the structure of the company must be configured. In our case, the request is submitted by the administrator who has a manager configured with the HR app.
To check the assignment policy, click Test on the policy form.
On the form that opens:
- In the Policy field, select the created assignment policy (we select Manager of the user who created the request).
- In the Object ID field, select the object on which to test the policy. In our case this is a request that was created by the administrator.
- Click Test.
At the bottom of the window, you can see the overall result of testing (the Result Get and Result Convert fields). The result is returned as a dictionary (from python programming language).
Below you can see an Assign Debug Log. It displays the result of testing each rule of each policy step by step.
Set Up Automatic Assignment
Now let's set up the request route so that at the certain stage the manager is automatically assigned. In our case: set up Simple Request to automatically assign the manager of the user who created the request on the route from Draft to Sent.
Make sure that the following module is installed:
- Generic Request (Actions) - this module allows to perform automatic actions when the request navigate along the route.
Click Requests in the main menu on the left. Then click Configuration -> Types.
Select the type of request where you want to set up automatic assignment.
On the request type form, click Routes.
Select the route that the assignment should take. On the route form, click Actions.
On the actions page, click Create and fill out the form:
- Enter the action name.
- Select the type of action - Assignment.
- Click the Assign tab, select the Policy Assign Type. Next to the Assign policy field select the created assignment policy.
- Click Save.
Now, when Simple Request moves along the route from the Draft to Sent stage, the manager of the user who submitted the request will be automatically assign as a responsible person.