Deluge Script to fetch resolution content and add as a note when a request is reopened

Deluge Script to fetch resolution content and add as a note when a request is reopened

1. Create a Global function using the below script and save. Make sure that the application URL and Technician API key are mentioned correctly.

Global Function:


configuration = Map();
configuration.put("url","http://pcr90tz4pn:8080");
configuration.put("technicianKey","8AB28CFE-31EC-4047-BB4E-BA7006BDE24E");

return configuration;


2. Under Admin - > incident Management - > Request custom function, create a request custom function using the below script and save. Make sure that the Global function used in the below script is mentioned correctly as per the Global function created above.

Script:

configuration = global_function_4();

helpdeskID = context.get("instance").get("id");
workorderid = requestObj.get("id");
returnObj = Map();

if( !requestObj.get("resolution").get("content").isNull() &&!requestObj.get("resolution").get("content").equalsIgnoreCase("null")){
  notes_content = requestObj.get("resolution").get("content");

  notes_input = {
    "note": {
      "description": notes_content,
      "show_to_requester": false,
      "notify_technician": false,
      "mark_first_response": false,
      "add_to_linked_requests": false
    }
  };

  response = invokeurl
  [
    url: configuration.get("url") + "/api/v3/requests/"+workorderid+"/notes"
    type: POST
    parameters: {"input_data":notes_input}
    headers: {"authtoken":configuration.get("technicianKey"),"PORTALID":helpdeskID}
  ];

  if(response.get("response_status").get("status_code") == 2000) {
    returnObj.insert("result":"success","message":"Notes Added Successfully!!");
    }
  else{
    returnObj.insert("result":"failure", "message":response.get("response_status").get("messages").get(0).get("message"));
  }
}
else{
  returnObj.insert("result":"success","message":"No Content to add as notes!!");
}
return returnObj;
 


3. Once done, create a custom trigger as shown in the attached screenshot (Trigger.png).


4. So, whenever a closed request is reopened, the content added in the resolution field will be added as a note.
                New to ADManager Plus?

                  New to ADSelfService Plus?