Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Send Updated fields in the payload

Vamshi_ch123
Tera Contributor

Hi @Sandeep Rajput 

 

I am currently trying to send the updated fields to a third-party application. However, when I update any field using a business rule, I notice that all values, except the updated one, appear as null. Similarly, the same issue occurs, and the corresponding fields become blank in the third-party application.

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here

    gs.info("Check Exe @@@");



    var restMessage = new sn_ws.RESTMessageV2('SS', 'Update Ticket');

    restMessage.setStringParameterNoEscape('id', current.u_ticked_id);

    restMessage.setStringParameterNoEscape('token', 'wjsjjjjjjjjjjjjjjjjjjjj');



    if (current.u_environment) {

        restMessage.setStringParameterNoEscape('environment', current.u_environment);

    }



    if (current.state) {

        restMessage.setStringParameterNoEscape('status', current.state);

    }



    if (current.category) {

        restMessage.setStringParameterNoEscape('state', current.category);

    }



    if (current.sys_updated_by == current.u_pst_assignee.user_name || current.sys_updated_by == current.assigned_to.user_name) {

        restMessage.setStringParameterNoEscape('note', current.comments);

    }



    var requestBody = restMessage.getRequestBody();

    gs.info("Request Payload sent to third party: " + requestBody);



    gs.info('Check Exe here@@@');



    var response = restMessage.execute();

    var responseBody = response.getBody();

    var httpStatus = response.getStatusCode();

   

    current.work_notes = responseBody;

    gs.log("Check Exe @@@ Resp " + responseBody);



    if (httpStatus === 200) {

        // Proceed with processing the response

        var responseJSON = responseBody.substring(10, responseBody.length - 1);

        var parsedJSON = JSON.parse(responseJSON);



        var targetIncidentNumber = parsedJSON['number'];

        var targetIncidentSysId = parsedJSON['sys_id'];

        var targetNumber = parsedJSON['u_ticked_id'];

        var env = parsedJSON['u_environment'];

        var notes = parsedJSON['comments'];



        var logString = 'Check Exe @@@ Target Incident Number - ' + targetIncidentNumber +

                        '\nTarget Incident Sys ID - ' + targetIncidentSysId +

                        '\nTarget Incident ID - ' + targetNumber +

                        '\nEnvironment - ' + env +

                        '\nNotes - ' + notes;



        gs.log(logString, 'BR- Test');

    } else {

        gs.error("Check Exe @@@ Error: HTTP Status " + httpStatus);

    }



})(current, previous);

 

for ex : when I change the environment all other values are getting blank

custom_fields":[{"id":"description","value":null},{"id":"waiting_for_reason","value":null},{"id":"severity","value":"low"},{"id":"environment","value":"staging"},{"id":"state","value":"1"},{"id":"status","value":null},{"id":"note","value":null} 

 

Thank you

6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@Vamshi_ch123 Please update your business rule as follows and check if the following script works for you.

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here

    gs.info("Check Exe @@@");



    var restMessage = new sn_ws.RESTMessageV2('SS', 'Update Ticket');

    restMessage.setStringParameterNoEscape('id', current.u_ticked_id+'');

    restMessage.setStringParameterNoEscape('token', 'wjsjjjjjjjjjjjjjjjjjjjj');



    if (current.u_environment) {

        restMessage.setStringParameterNoEscape('environment', current.u_environment+'');

    }



    if (current.state) {

        restMessage.setStringParameterNoEscape('status', current.state+'');

    }



    if (current.category) {

        restMessage.setStringParameterNoEscape('state', current.category+'');

    }



    if (current.sys_updated_by == current.u_pst_assignee.user_name || current.sys_updated_by == current.assigned_to.user_name) {

        restMessage.setStringParameterNoEscape('note', current.comments+'');

    }



    var requestBody = restMessage.getRequestBody();

    gs.info("Request Payload sent to third party: " + requestBody);



    gs.info('Check Exe here@@@');



    var response = restMessage.execute();

    var responseBody = response.getBody();

    var httpStatus = response.getStatusCode();

   

    current.work_notes = responseBody;

    gs.log("Check Exe @@@ Resp " + responseBody);



    if (httpStatus === 200) {

        // Proceed with processing the response

        var responseJSON = responseBody.substring(10, responseBody.length - 1);

        var parsedJSON = JSON.parse(responseJSON);



        var targetIncidentNumber = parsedJSON['number'];

        var targetIncidentSysId = parsedJSON['sys_id'];

        var targetNumber = parsedJSON['u_ticked_id'];

        var env = parsedJSON['u_environment'];

        var notes = parsedJSON['comments'];



        var logString = 'Check Exe @@@ Target Incident Number - ' + targetIncidentNumber +

                        '\nTarget Incident Sys ID - ' + targetIncidentSysId +

                        '\nTarget Incident ID - ' + targetNumber +

                        '\nEnvironment - ' + env +

                        '\nNotes - ' + notes;



        gs.log(logString, 'BR- Test');

    } else {

        gs.error("Check Exe @@@ Error: HTTP Status " + httpStatus);

    }



})(current, previous);

Hope this helps.

Hi @Sandeep Rajput,

The current solution is functional; however, when updating other fields, the note value remains blank in the response body. Despite successfully passing comments added by the assigned_to person to the third-party "note" string field, only this field returns a null output, while other fields are being updated.

 

After updating comments:

{"id":"environment","value":"production"},{"id":"state","value":"3"},{"id":"status","value":"10"},{"id":"assign_to","value":false},{"id":"note","value":"Test Comment"}

 

After Updating state or any other fields

{"id":"environment","value":"production"},{"id":"state","value":"2"},{"id":"status","value":"10"},{"id":"assign_to","value":false},{"id":"note","value":null}

 

Thank you

@Vamshi_ch123 Could you please share what values you are seeing while printing the request and response body in logs?

Hi, @Sandeep Rajput ,

 

When I update the state/any field this is the payload I can see in the logs

 

Request Payload sent to third party: {"id": "undefined","token": "wwwwwwwwwwww","environment": "production","status": "10","state": "1","note": ""}

 

When I update the comments

Request Payload sent to third party: {"id": "undefined","token": "wwwwwwwwwwww","environment": "production","status": "10","state": "1","note": "test comment"}

 

Thank you