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

How to automatically create multiple child requests from a parent request with a configurable JSON file (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'.

Steps

1. Download the file from the attachment, extract it and place it under ManageEngine\ServiceDeskPlus-MSP\integration\custom_scripts.

1a. if you already have a configuration.json, the one in the file need not be replaced. If you do not have it, place it, edit it and fill the technician key and URL
1b. Edit ChildRequestsV3.json and configure the parent and child request. Example below

2. Go to Admin >> Custom Trigger >> Create a new trigger with a condition and specify the below script name

py MultipleRequestsV3.py ChildRequestsV3.json $COMPLETE_V3_JSON_FILE



3. When the condition satisfies, child requests will be created and the request IDs will be added in the notes and history tab

Important Note:
1. Make sure that the criteria configured for the parent request in the custom trigger do not match the child requests during creation. If it matches, then it will end up in a loop, where the criteria will match and requests will be created in the loop.
2.Execution Command: py MultipleRequestsV3.py ChildRequestsV3.json $COMPLETE_V3_JSON_FILE
3. In the ChildRequestsV3.json Account parameter should be always set like the default. 

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
Note: The variable names enclosed within the dollar symbol are those of the fields that are fetched from the parent request.

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

For moving the UDF fields from parent request to child request

{
  "Default Request": [
    {
      "request": {
        "subject": "Create a VPN Account for the employee $udf_fields,$udf_sline_1201 and parent Id :  $id",
        "requester": "$requester",
 "udf_fields": {
  "udf_sline_1201": "$udf_fields,$udf_sline_301",
  "udf_sline_301": "$udf_fields,$udf_sline_1201"
 }
      }
    }
  ]
}

{
  "Default Request": [
    {
      "request": {
        "subject": "Create a VPN Account for the employee $udf_fields,$udf_sline_1201 and parent Id :  $id",
        "requester": "$requester",
         "udf_fields": "$udf_fields"
      }
    }
  ]
}