I have a tasks created automatically after receiving a request with additional fields (custom date). Is
it possible to set the
start date from an additional field and set a reminder 15 minutes
before?
I tried with this script but it returns errors {"result":"Failure","message":"Task fetch failed"}
---------------------------------
global_function_10 is
--------------------------------------
configuration = global_function_10();
dateOfJoining = "udf_date_904";
helpdeskID = context.get("instance").get("id");
workorderid = requestObj.get('id');
technicianKey = configuration.get("technicianKey");
json_data = {"list_info": { "row_count": "30"} };
info json_data;
taskresponse = invokeurl
[
url: configuration.get('url') + "/api/v3/requests/"+workorderid+"/tasks"
type: GET
headers: {"authtoken":configuration.get("technicianKey"),"PORTALID":helpdeskID}
parameters: {"input_data":json_data}
];
successList = List();
failureList = List();
resultantJson = Map();
schedule_end_date = requestObj.get("udf_fields").get(dateOfJoining).get("value");
additionalField = requestObj.get("udf_fields").get(dateOfJoining).get("display_value").toDateTime();
additionalField = additionalField.subDay(7);
additionalField2 = additionalField.subDay(1);
schedule_start_date = additionalField.toString().unixEpoch("Europe/Warsaw");
if("success".equalsIgnoreCase(taskresponse.get("response_status").get("status")))
{
taskData = taskresponse.get('tasks');
for each task in taskData{
input_data = {
"task": {
"scheduled_start_time": {"value":schedule_start_date},
"scheduled_end_time": {"value":schedule_end_date}
}
};
response = invokeurl
[
url: configuration.get('url') + "/api/v3/requests/"+workorderid+"/tasks/" + task.get("id")
type: PUT
headers: {"authtoken":configuration.get("technicianKey"),"PORTALID":helpdeskID}
parameters: {"input_data":input_data}
];
if("success".equalsIgnoreCase(response.get("response_status").get("status")) ){
successList.add(task.get('id'));
}
else{
failureList.add(task.get('id'));
}
}
msg = "";
if(!successList.isEmpty()){
msg = "Zadania zostały pomyślnie zaktualizowane: " + successList;
}
if(!failureList.isEmpty()){
msg = msg + ", Zadania niezaktualizowane: " +failureList;
}
resultantJson.insert("result": "Success","message": msg);
}
else{
resultantJson.insert("result": "Failure","message": "Task fetch failed");
}
return resultantJson;