How to create multiple child requests from a parent request with a configurable JSON file using Custom Menu(V3)

How to create multiple child requests from a parent request with a configurable JSON file using Custom Menu(V3)

This is a sample Python script to automatically trigger the creation of multiple child requests from a parent request, based on the request template chosen. The request ID of the child requests will be added as a Note in the parent request.

This is achieved using an API call to create a request in ServiceDesk Plus. Details of the child requests are stored in a JSON file and provided as the primary parameter to the script. The parent request details are stored as a JSON object in a file and its path is provided as the second parameter.  A separate API  is used to add the request ids of the child requests as notes to the Parent request. This is achieved using Request Custom Triggers and the link here will provide more information on that.

Use Case: When certain Services are requests by a user, under the service category 'User Management', multiple child requests have to be triggered. In the sample shown above, a single child request will be triggered when a Service Request is created using the template 'Request to start the process associated to a new hire'.

Updating the Configuration file:
The configuration file has the name of the request template of the parent request and the list of child requests to be created. The script matches the template 's name received from the parent request against the name in the JSON file and creates child requests accordingly. The Child request details are stored in the configuration file labeled "ChildRequestsV3.json", in the format shown below.

{
  "Request to start the process associated to a new hire": [
    {
      "request": {
        "subject": "Create a VPN Account for the employee $udf_fields,$udf_sline_19 - Parent ID : $id",
        "requester": "$requester"
      }
    }
  ]
}
The highlighted text is the name of the template, 
$udf_fields,$udf_sline_19 additional field values from the parent request
Refer here for more parameters

Example: New hire Template UI is as below


API format after adding the request is as below



Now if you would like to move the User information to the child request just configure the ChildRequestsV3.json like this

{
  "New Hire": [
    {
      "request": {
        "subject": "Create a VPN Account for the employee $udf_fields,$udf_sline_19 - Parent ID : $id",
        "requester": "$requester",
        "description":"Employee Name: $udf_fields,$udf_sline_19 \n Mobile : $udf_fields,$udf_sline_23  \n Department : $udf_fields,$udf_sline_20 \n Seating Location : $udf_fields,$udf_sline_21 \n Joining Date : $udf_fields,$udf_date_901,$display_value" 
        
      }
    }
  ]
}

For example, if you want to populate employee name to the child request subject just add $udf_fields,$udf_sline_19 this will replace with exact value from the parent request when child request is created
Note: The variable names enclosed within the dollar symbol are those of the fields that are fetched from the parent request.

Execution steps:
1. Download attached zip
2. Move all files to sdp_home/integration/custom_scripts folder
Note: Don't move configuration.json if there is a file with same name exists
3. Edit configuration.json update url and technicianKey
3. Add the template names and child request details in the JSON configuration file labeled ChildRequestsV3.json.
4. Configure the script and its parameter under the Admin -> Custom Menu. The script file to run parameter will be set as shown below.
py MultipleRequestsV3.py ChildRequestsV3.json $COMPLETE_V3_JSON_FILE
I've attached a screenshot showing a sample implementation below.



A short guide on setting up python is available here

                  New to ADSelfService Plus?