Setting Duration Field value From Flow designer variable to Scripted rest API

BHARATHS
Tera Contributor

Hello Everyone,

 

I am trying to create a SLA from UAT to Dev, if record producer submitted means automatically SLA will get created. As of now Sla getting created but Duration field and Schedule field is not getting updated. I have provided now using flow designer script in UAT and scripted rest Api in Dev to receiving data.

 

Set FLow Variable:

 

var crSla = {
    name: fd_data._1__get_catalog_variables.u_name_sla.toString(),
    type: fd_data._1__get_catalog_variables.u_sla_type.toString(),
    time: fd_data._1__get_catalog_variables.u_time_zone.toString(),
    schedule: fd_data._1__get_catalog_variables.u_schedule.toString(),
    duration: fd_data._1__get_catalog_variables.u_schedule_duration.toString()

};
 

return crSla;
 
 
Scripted Rest API:
 
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    this.status = '200';
    var responseBody = {};
    var error;

    try {

        var requestBody = request.body.data;

       
        var sla = new GlideRecord('contract_sla'); // Create new sla
        sla.initialize();
        sla.name = requestBody.name;
        sla.target = requestBody.type;
        sla.duration = requestBody.duration;
        sla.schedule = requestBody.schedule;
        sla.timezone_source = requestBody.time;
        sla.collection = requestBody.table;
        sla.sys_scope = requestBody.scope;
        // sla.stop_condition = requestBody.stop_condition;
        //sla.start_condition = requestBody.start_condition;



        var slaSysId = sla.insert();
        responseBody.status = 'success';
        responseBody.sys_id = slaSysId;
    } catch (e) {
        responseBody.status = 'error';
        responseBody.message = e.message;
    }

    response.setBody(responseBody);
})(request, response);
 
 
could you please check the above script and provide me a solution.
 
Thanks
Bharath S
2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

If the SLA Duration and Schedule fields are not populated, you need to go back to the source and first log the values the script is receiving for u_schedule and u_schedule_duration.  On the contract_sla table, the schedule field is a reference to the Schedule table, so you need to provide the sys_id of a valid record on this table.  The duration field is, unsurprisingly, the type of Duration.  If the variable is also this type, you may need to use server methods like dateNumericValue() and setDateNumericValue() instead of converting it to a string.

Ankur Bawiskar
Tera Patron
Tera Patron

@BHARATHS 

but why are you creating SLA via script?

those are meant to be configured manually by admins in DEV and then can be migrated via update set to higher instance

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader