Adding values from custom fields to task fields

Adding values from custom fields to task fields

I have a tasks created automatically after receiving a request with additional fields. Is it possible to copy their content to the task description, 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"}

  1. configuration = global_function_10();
    dateOfJoining = "udf_date_904";

    helpdeskID = context.get("instance").get("id");
    workorderid = requestObj.get('id');
    json_data = {"list_info": { "row_count": "300"} };

    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);
    schedule_start_date = additionalField.toString().unixEpoch("Europe/Warsaw");

    info schedule_start_date;

    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 = "List of Tasks successfully edited: " + successList;
        }
        if(!failureList.isEmpty()){
            msg = msg + ",   List of Tasks failed to Edit: " +failureList;
        }
        resultantJson.insert("result": "Success","message": msg);
    }
    else{
        resultantJson.insert("result": "Failure","message": "Task fetch failed");

    }


                New to ADSelfService Plus?