How to implement dynamic request approval using FAFR_UserList and custom triggers (Latest Approval format)

How to implement dynamic request approval using FAFR_UserList and custom triggers (Latest Approval format)

This is a sample script written in Deluge to handle Conditional Approvals for Incident \ Service Requests, through Custom Triggers using Field and Form Rules.  One of the advantages of using this script that no modification in the script is required to get it working.  The approvers can be configured through FAFR and this is easier to modify without server access.

Use Case:  
Let's assume that when users request a service from a long list of offerings in a large organization, it makes no sense if all the services go through the same set of approval processes. As most of the services would have a different set of approvers and approval levels, it is mandatory to customize the request approval processes.  This post helps IT, Administrators, dynamically set approvers at different approval stages directly in the request without the need to configure them in the template. With the help of Field and Form rules, the list of approvers is set in the request additional fields used to send approvals.

FAFR script will load all the users in the organisation with their user ids.

Execution Steps:
1.  Create new additional fields for the request to hold the approver information and update the API name in the script. 
Goto:  Admin > Incident Additional Fields

2.  Each stage must be configured as a separate additional field.

3.  Connect to Db and execute the below query.  Restart your instance for this to take effect.
update globalconfig set paramvalue=true where parameter='AllowUserAPIInRequesterLogin';

4.  Go to Admin > Service Templates > Select a particular template > Field and Form Rules > Rule execution - On Create / Edit > Event - "On Form Load" >> Action > Execute Script > Use the FAFR script.
var fafrKeyList = ["WorkOrder_Fields_UDF_CHAR1", "WorkOrder_Fields_UDF_CHAR10", "WorkOrder_Fields_UDF_CHAR13", "WorkOrder_Fields_UDF_CHAR2", "WorkOrder_Fields_UDF_CHAR4"];
var selectMultiple = true;


function listUsers(fafrKey) {
    var cs_value = $CS.getValue(fafrKey);
    $CS.referField(fafrKey, "users", {
        url: "/api/v3/users",
        multiple: selectMultiple,
        needID: true
    if (cs_value !== "") {
        var arr = cs_value.split(",");
        var arr_length = arr.length;
        var list = [];
        for (var i = 0; i < arr_length; i++) {
                id: arr[i],
                text: arr[i]
        $CS.element(fafrKey).select2("data", list);

5.  Similarly set values for the required number of stages and move status to "Waiting for approval".

6.  Download the attached scripts.  Copy the contents into Request custom functions.

7.  Goto Admin > Request Custom Function > Custom Function > New > Paste the "setApprovals.txt" content and save it with a name

8.  Configure a custom trigger to get invoked when the "Status" is "Waiting for approval".  Go to Admin > Custom Trigger > give a trigger name > execute Custom Function > Select the Custom Function the we created and set the criteria as "Status=Waiting for approval"

      New to ADManager Plus?

        New to ADSelfService Plus?