Add Approvals to request when all the associated tasks are completed.

Add Approvals to request when all the associated tasks are completed.

Requirement:
Request approvals have to be added only after all the associated tasks of a request are completed.
If the approvals are added via the request workflow, then it would be automatically triggered when a request is created.  To avoid this, we need to add the approvals in request additional fields.

These can either be added directly or a FAFR script can be used to 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.
  2. Goto:  Admin > Incident Additional Fields

  3. Each stage must be configured as a separate additional field.
  4. Connect to Db and execute the below query.  Restart your instance for this to take effect.
    1. update globalconfig set paramvalue=true where parameter='AllowUserAPIInRequesterLogin'
  5. Go to Admins > Status > Create a custom request status "Waiting for approvals".
  6. 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.
    1. 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;
      
      fafrKeyList.forEach(listUsers);
      
      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++) {
                  list.push({
                      id: arr[i],
                      text: arr[i]
                  });
              }
              $CS.element(fafrKey).select2("data", list);
          } }
  7. Goto Admin > Developer Space > Global function > New > Paste the content from the attachment  GF_4 - Configuration.txt  and save it with a name.
  8. Update the URL and integration key in the script. 
    1. You can get the integration key under Admin > Integrations > Integration Key > New
    2. Please use an integration key with admin privilege, as there wont be any role related permission issues. 

    3. Update the integration key in the global function.

  9. Goto Admin > Developer Space > Request Custom Function > New > Paste the "setApprovals.txt" content and save it with a name.
  10. Goto Admin > Developer Space > Task Custom Functions. Create a new function.
    1. Refer to the attached script. (addApprovals.txt.)
    2. Update the global function count and custom request status name in the script as per your instance.
  11. Configure Task custom trigger to get executed on every task being closed with "Module" as "Request".
  12. Configure Request custom trigger to get executed every time the request is moved to the custom status.


                    New to ADSelfService Plus?

                      • Related Articles

                      • How to close associated incident requests of change request automatically

                        This post describes the use of a python script to close change that are in a specific stage using Custom Schedules. Use Case: There may be a scenario where number of Change Requests that have got closed and the associated incident is still in open ...
                      • Close all associated tasks when a request is closed

                        Requirement: When a request is closed, it is necessary to close all of its related tasks. Usecase: In an organizational context, a request can involve multiple technicians, resulting in its segmentation into distinct tasks. When the request is marked ...
                      • How to populate request details on associated tasks.

                        This sample script is used to update request field values into tasks associated with request templates The Request details are stored as a JSON Object in a file and its path is provided as input to the Script. This can be used in the application ...
                      • How to automatically create multiple tasks in a change request with a configurable JSON file.

                        Note:  Attached script will not work beyond 11138 SDP Version. ​ This is a sample Python script  to automatically  create multiple tasks within a change request  with a configurable JSON file. This is achieved  using an API call to create a task in ...
                      • Problem and Associated incidents with Request id

                        MSSQL SELECT "prob"."PROBLEMID" AS "Problem ID", max("prob"."TITLE") AS "Title", longtodate(max("prob"."REPORTEDTIME")) AS "Reported Date", max("prob"."DUEBYTIME") AS "DueBy Date", max("orgaaa"."FIRST_NAME") AS "Reported by", max("probf"."UDF_CHAR1") ...