Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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
0 REPLIES 0