Creating a Timer via Custom Function

Creating a Timer via Custom Function

Good day SDP Community, 

We are attempting to use this custom function to handle the automated emails we receive from our internal PRTG architecture. (PRTG is network monitoring software & sends emails when network assets fall offline and when they reconnect.) 

These generated emails are then picked up by Business rules to further facilitate the handling of the created ticket. We use email parsing commands example: (@@Template = PRTG@@) to drive the template, mode, and other details of the incoming ticket. 

We have a business rule that takes the email from PRTG when an asset has restored connection and automatically closes the original ticket for the device being offline. The code for that custom function is: 

  1. alertIdentificationUdfKey = "udf_char149";
  2. closure_code = "PRTG Auto Close";
  3. /*Please provide the description of the note content*/
  4. noteDescription = "The alert has been cleared in PRTG, hence closing the request";
  5. deviceId = requestObj.get("udf_fields").get(alertIdentificationUdfKey);
  6. requests = zoho.sdp.invokeurl
  7. [
  8. url :"/app/" + context.get("instance") + "/api/v3/requests"
  9. type :GET
  10. parameters:{"input_data":{"list_info":{"search_criteria":{{"field":"udf_fields." + alertIdentificationUdfKey,"condition":"contains","values":{deviceId},"logical_operator":"AND"},{"field":"status.in_progress","condition":"is","value":true,"logical_operator":"AND"}},"row_count":1,"sort_fields":{{"field":"display_id","order":"desc"}}}}}
  11. ];
  12. info requests;
  13. if(requests.get("requests") != null && requests.get("requests").size() > 0)
  14. {
  15. requestId = requests.get("requests").get(0).get("id");
  16. closeRequest = zoho.sdp.invokeurl
  17. [
  18. url :"/app/" + context.get("instance") + "/api/v3/requests/" + requestId
  19. type :PUT
  20. parameters:{"input_data":{"request":{"status":{"name":"Closed"},"closure_info":{"closure_code":{"name":closure_code}}}}}
  21. ];
  22. if(closeRequest.get("request") != null)
  23. {
  24. addNote = zoho.sdp.invokeurl
  25. [
  26. url :"/app/" + context.get("instance") + "/api/v3/requests/" + requestId + "/notes"
  27. type :POST
  28. parameters:{"input_data":{"request_note":{"description":noteDescription}}}
  29. ];
  30. }
  31. }
  32. return requestObj;
^This code currently works perfectly**

What we want to know is, if it's possible to add a "timer or countdown" element to this code. 

Essentially, we want to execute the above script of "auto-closing the PRTG ticket" only if the "returned to Online status" email is received within a given time frame. 

Example: 

Ticket for Server XYZ failing to respond to ping is created at 12:00 local time, if the email from PRTG is received within 15 minutes (on or before 12:15 local time) we want to execute the code above. 

If the email from PRTG is received after the 15-minute mark (on or after 12:16 local time) - do not execute the above code.

*The time of ticket creation" is irrelevant the variable we want to use is the "time frame" ex. (15-minutes not a specific set of times of the day) we'd like to add into the code. 

Any and all help is greatly appreciated! 

Best Regards, 

Bradley 


                New to ADSelfService Plus?