When Change is created in ServiceExchange Ebond is happening but from our end it's not happening.

NishantaL
Tera Contributor

We are currently seeing two different errors while sending the Change Request from ServiceNow to SX:

  1. If the Requested Start Date or Planned Start Date is in the past when the Change moves from New to Assess, the POST Business Rule is triggered and SX returns the below error:

"Back date not allowed!" – HTTP 400 Bad Request

  1. If the dates are valid/future dates and the Change moves from New to Assess before the requested/planned start date, we receive another error:

"GBP Risk Assessment is not allowed as per admin preference" – HTTP 400 Bad Request

The important point is that the eBonding should happen only when the Change moves to Assess. From ServiceNow, the state sent to SX should therefore be -4 (Assess). However, we can see that 3 -Closed ( ITSM backend value) is being sent instead.

My doubt is whether the incorrect state value 3 is being triggered because of the Planned Start Date/date validation logic, or whether it is coming from one of our Outbound Business Rules/integration scripts.

We have multiple Outbound Business Rules, including the POST Business Rule responsible for creating the Change in SX. I can share the conditions and scripts for review.

From where should I start investigating to identify why state 3 is being sent instead of -4?

This is outbound post Async BR and conditions is: corr ID is empty and created by is not integration user and state is not new.

function normalizeString(str) {

    if (!str)

        return "";

    // Remove only extra whitespace

    var desc = str.replace(/\s+/g, ' ');
        var cleaned = desc
            .replace(/\\/g, '\\\\')
            .replace(/"/g, '\\"')
            .replace(/\r\n|\r|\n/g, '\\n');

    return cleaned;

}



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

   var cleaneddes = normalizeString(current.description);
    var cleanedsd= normalizeString(current.short_description);
    var cleanedjus= normalizeString(current.justification);
    var cleanedimp= normalizeString(current.implementation_plan);
    var cleanedback= normalizeString(current.backout_plan);
    var cleanedtest= normalizeString(current.test_plan);
    gs.info("descriptioncleaned-" + cleaneddes);
    gs.info("shortdescriptioncleaned-" + cleanedsd);
    var r = new sn_ws.RESTMessageV2('Outbound Change_SX Ebonding', 'POST');
    r.setStringParameterNoEscape('short_description', cleanedsd);
    r.setStringParameterNoEscape('description', cleaneddes);
    r.setStringParameterNoEscape('number', current.number);
    r.setStringParameterNoEscape('type', current.type);
    r.setStringParameterNoEscape('category', current.category);
    r.setStringParameterNoEscape('subcategory', current.u_subcategory);
    r.setStringParameterNoEscape('assignment_group', current.assignment_group.getDisplayValue());
    r.setStringParameterNoEscape('requested_by', current.requested_by.getDisplayValue());
    r.setStringParameterNoEscape('state', current.state);
    r.setStringParameterNoEscape('Justification', cleanedjus);
    r.setStringParameterNoEscape('Implementation_Plan', cleanedimp);
    r.setStringParameterNoEscape('risk', current.risk);
    r.setStringParameterNoEscape('Backout_Plan', cleanedback);
    r.setStringParameterNoEscape('Test_Plan', cleanedtest);
    r.setStringParameterNoEscape('Planned_Start_Date', current.start_date);
    r.setStringParameterNoEscape('Planned_End_Date', current.end_date);
    var response = r.execute();
    var responseBody = response.getBody();
    var status = response.getStatusCode();
    gs.info('statusebondchg' + status);
    gs.info('responsebondchg' + current.number+''+responseBody);
    //var result=JSON.stringify(responseBody);
    var res = JSON.stringify(responseBody);
    var result = JSON.parse(res);
    result = JSON.parse(result);
    gs.info("POSTRESchg" + res);
    gs.info("POSTRESPARSEDchg" + result);

    gs.info("POSTRESULTchg" + result.u_correlation_id);
    current.setWorkflow(false);
    current.correlation_id = result.u_correlation_id.toString();
    current.update();


})(current, previous);

PUT BR might be the reason behind this as-
corr ID is empty and updated by is not integration user and state changes or state is cancelled/state is review / state is schedules.

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

    gs.info("chgstatechangebr1" + current.number);

    gs.info("chgstatechangebr2" + current.number);
    if (current.state != 3) {
        var r = new sn_ws.RESTMessageV2('Outbound Change_SX Ebonding', 'PUT');
        gs.info("chgstatechangebr3-" + current.number + ": " + current.state);
        var body = {
            "itemNumber": current.correlation_id.toString(),
            "clientChangeNumber": current.number.toString(),
            "changeState": current.state.toString(),
            "Change_Type": current.type.toString(),
            "assignedGroupName": current.assignment_group.getDisplayValue(),
            "cabDate": current.cab_date.toString()
        };
        r.setRequestBody(JSON.stringify(body));
        var response = r.execute();
        var responseBody = response.getBody();
        var status = response.getStatusCode();
        gs.info('chgstatusebondPUT' + status);
        gs.info('chgresponsebondPUT' + responseBody);
    } else {
        var r = new sn_ws.RESTMessageV2('Outbound Change_SX Ebonding', 'PUT');
        gs.info("chgstatechangebr7");
        var body = {
            "itemNumber": current.correlation_id.toString(),
            "clientChangeNumber": current.number.toString(),
            "changeState": current.state.toString(),
            "closeCode": current.close_code.toString(),
            "Change_Type": current.type.toString(),
            "assignedGroupName": current.assignment_group.getDisplayValue(),
            "cabDate": current.cab_date.toString(),
            "activityLogEntry": current.close_notes.toString()
        };
        r.setRequestBody(JSON.stringify(body));
        var response = r.execute();
        var responseBody = response.getBody();
        var status = response.getStatusCode();
        gs.info('chgstatusebondPUT' + status);
        gs.info('chgresponsebondPUT' + responseBody);
    } )(current,previous);



0 REPLIES 0