How to automatically create multiple child requests from a parent request with a configurable JSON file (V3) (Copying parent UDF fields, Resource Information and parent attachments)

How to automatically create multiple child requests from a parent request with a configurable JSON file (V3) (Copying parent UDF fields, Resource Information and parent attachments)

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 with a new hire'.

Note: For builds above 11300 use Files_latest.zip

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 labelled "ChildRequestsV3.json", in the format shown below.

{
  "New Hire": [
    {
      "request": {
         "subject": "Request a new Laptop/Desktop for the employee $udf_fields,$udf_sline_304 parentId : $id",
        "description": "Request a new Laptop/Desktop for the employee $udf_fields,$udf_sline_304",
"requester": "$requester",
        
"template":{
"name":"Copy-Hire"
},
  "category":{
"name":"Hardware"
},
"subcategory":{
"name":"Deskphone Request"
},
"item":{
"name":"Installation"
}
    }
}

  ]
}
The highlighted text is the name of the template, 
$udf_fields,$udf_sline_304 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 New Hire request is as below




Order a Laptop or Desktop template Ui as follows





And API format for the Order a Laptop or Desktop template Ui as follows






Now if you would like to move the udf fields/resource details information to the child request just configure the ChildRequestsV3.json like this

{
  "New Hire": [
    {
      "request": {
        "subject": "$subject testingggggggggg $udf_fields,$udf_pick_302 2853454 $udf_fields,$udf_sline_304 ",
        "description": "$udf_fields,$udf_pick_305 ---   $udf_fields,udf_date_303,$value -- $udf_fields,$udf_sline_304  --- $resources,$res_901,$qstn_simple_310,$name ---  $resources,$res_901,$qstn_simple_309,$name ----  $resources,$res_902,$qstn_text_306,$value ---- $resources,$res_902,$qstn_select_308,$name --- $resources,$res_902,$qstn_simple_307,$name",
"requester": "$requester",
        "udf_fields": {
"udf_pick_305": "$udf_fields,$udf_pick_305",
"udf_date_303": "$udf_fields,udf_date_303",
"udf_multiselect_601": "$udf_fields,$udf_multiselect_601",
"udf_sline_304": "$udf_fields,$udf_sline_304",
"udf_sline_301": "$udf_fields,$udf_sline_301",
"udf_sline_307": "$udf_fields,$udf_sline_307",
"udf_sline_308": "$udf_fields,$udf_sline_308",
"udf_sline_306": "$udf_fields,$udf_sline_306",
"udf_pick_302": "$udf_fields,$udf_pick_302",
"udf_multiselect_1202":"$udf_fields,$udf_multiselect_1202"
  },
  
  "resources": {
 
  "res_902": {
"qstn_text_306": "$resources,$res_902,$qstn_text_306",
"qstn_select_308": "$resources,$res_902,$qstn_select_308",
"qstn_simple_307": "$resources,$res_902,$qstn_simple_307"
},
  "res_901": {
"qstn_select_903": "$resources,$res_901,$qstn_select_903",
"qstn_select_904":"$resources,$res_901,$qstn_select_904",
"qstn_simple_310": "$resources,$res_901,$qstn_simple_310",
"qstn_check_905": "$resources,$res_901,$qstn_check_905",
"qstn_text_907": "$resources,$res_901,$qstn_text_907",
"qstn_check_906": "$resources,$res_901,$qstn_check_906",
"qstn_simple_902": "$resources,$res_901,$qstn_simple_902",
"qstn_simple_901": "$resources,$res_901,$qstn_simple_901",
"qstn_simple_309": "$resources,$res_901,$qstn_simple_309"
  }
},
"template":{
"name":"Copy-Hire"
},
  "category":{
"name":"Hardware"
},
"subcategory":{
"name":"Deskphone Request"
},
"item":{
"name":"Installation"
}
  
      }
}
  ]
}


"udf_date_303":"$udf_fields,$udf_date_303", ---> Parent UDF field information ($udf_fields,$udf_date_303) is moved to child udf_date_303 field


"qstn_simple_302":"$resources,$res_302,$qstn_simple_302", --> Parent resouce information ($resources,$res_302,$qstn_simple_302) is moved to child qstn_simple_302 field



Note : Form multiple requests to be created for the same template includes one more request JSON 

{
  "New Hire": [
    {
      "request": {
         "subject": "Request a new Laptop/Desktop for the employee $udf_fields,$udf_sline_304 parentId : $id",
        "description": "Request a new Laptop/Desktop for the employee $udf_fields,$udf_sline_304",
"requester": "$requester",
        
"template":{
"name":"Copy-Hire"
},
  "category":{
"name":"Hardware"
},
"subcategory":{
"name":"Deskphone Request"
},
"item":{
"name":"Installation"
}
    }
},
{
      "request": {
         "subject": "Request a new Laptop/Desktop for the employee $udf_fields,$udf_sline_304 parentId : $id",
        "description": "Request a new Laptop/Desktop for the employee $udf_fields,$udf_sline_304",
"requester": "$requester",
        
"template":{
"name":"Copy-Hire"
},
  "category":{
"name":"Hardware"
},
"subcategory":{
"name":"Deskphone Request"
},
"item":{
"name":"Installation"
}
    }
}

  ]
}


Note: For multiple templates Just add one more new template JSON to the ChidRequestsV3.json

{
  "New Hire 1": [
    {
      "request": {
        "subject": "$New Employe onboaring",
        "description": "New Employee onboarding",
"requester":"$requester",
  "category":"$category"
      }
},
{
      "request": {
        "subject": "$New Employe onboaring",
        "description": "New Employee onboarding",
"requester":"$requester",
  "category":"$category"
      }
}
  ],
  "New Hire 2": [
    {
      "request": {
        "subject": "$New Employe onboaring",
        "description": "New Employee onboarding",
"requester":"$requester",
  "category":"$category"
      }
},
{
      "request": {
        "subject": "$New Employe onboaring",
        "description": "New Employee onboarding",
"requester":"$requester",
  "category":"$category"
      }
}
  ]
}


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. A short guide on setting up python is available here

Execution steps:
1. Download the 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 the same name exists
3. Edit configuration.json update url and technicianKey
4. Add the template names and child request details in the JSON configuration file labeled ChildRequestsV3.json.
(This change is based on your requirement)
5. Configure the script and its parameter under the Admin -> Custom Triggers. 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.





                  New to ADManager Plus?

                    New to ADSelfService Plus?