Abort Submission when correlation ID does not contain 'xyz'

Naveen87
Tera Guru

Hello Developers,

 

We have OUTBOUND integration.

We send Incident data from X company which creates record on Y company.

Y company Incident come back & stores on correlation_id variable of X company.

 

To avoid any confusion b/w 2 e-bonding. I'm trying this.

 

I have a pre-fix on Y company incident number (Ex:- XYZ:INC123)

 

I have few line of codes in my BR to validate this.

I want to abort action , if any value to correlation_id field apart from "XYZ:INC") is received.

I tried below code, It gave an Invalid insert msg on incident form but still update the correlation_id .

 var correlation_id = current.correlation_id;
        if (correlation_id.includes("XYZ:INC")) {
            gs.addInfoMessage("Correlation ID contains 'EUWbond'");
        } else {
            // Field contains something else, show error message
            gs.addErrorMessage("Correlation ID must contain 'EUWbond'");
			current.setAbortAction(true);
        }

Attaching my complete BR. 

In BR I'm checking if correlation_id contains 'euwbond:INC' then good else through an error msg.

To test this I have modified line 21 to "123": I receive the error but unable to abort the update.

Please suggest how to abort this & accept which only contain (XYZ:INC).

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

    gs.info("Initially ");

    try {
        var r = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');  
        r.setStringParameterNoEscape('u_customer_ticket_id', current.number);
        r.setStringParameterNoEscape('u_shr_priority', current.priority);
        r.setStringParameterNoEscape('u_shr_assignment_group', current.getDisplayValue('assignment_group'));
       

        var response = r.execute();
        var responseBody = response.getBody();

        var jsonObj = JSON.parse(responseBody)
        var ticketid = jsonObj.result.u_partner_ticket_id;
        current.correlation_id = '123:' + ticketid;

        var correlation_id = current.correlation_id;

        if (correlation_id.includes("euwbond:INC")) {
            gs.addInfoMessage("Correlation ID contains 'EUWbond'");
        } else {
            // Field contains something else, show error message
            gs.addErrorMessage("Correlation ID must contain 'EUWbond'");
			current.setAbortAction(true);
        }

        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;



    }

})(current, previous);

Naveen87_0-1711361255923.pngNaveen87_1-1711361265301.png

 

8 REPLIES 8

I think this needs to be split in 2 separate business rules. 
Business rule on Before Insert should have conditions with Contains. 
Business rule on Before Update should have conditions with "changes" and "contains" 

 

Let's try that.

 

correlation id condition was added to avoid duplicate tickets creation on Y company.

It happened, when 1 euw group re-assigns the ticket to another euw group.

2 tickets were getting created on Y company.

To avoid this, correlation id = empty was added.

 

What will be the script in Insert & update?

Insert

Naveen87_0-1711375922629.png

 

 

update

Naveen87_1-1711375932029.png

 

 

SP22
Mega Sage
Mega Sage

Hi @Naveen87,

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

    gs.info("Initially ");

    try {
        var r = new sn_ws.RESTMessageV2('global.EUW Ebonding', 'POST Incident');  
        r.setStringParameterNoEscape('u_customer_ticket_id', current.number);
        r.setStringParameterNoEscape('u_shr_priority', current.priority);
        r.setStringParameterNoEscape('u_shr_assignment_group', current.getDisplayValue('assignment_group'));
       

        var response = r.execute();
        var responseBody = response.getBody();

        var jsonObj = JSON.parse(responseBody);
        var ticketid = jsonObj.result.u_partner_ticket_id;
        current.correlation_id = '123:' + ticketid;

        var correlation_id = current.correlation_id;

        if (correlation_id.includes("XYZ:INC")) {
            gs.addInfoMessage("Correlation ID contains 'XYZ:INC'");
        } else {
            // Field contains something else, show error message
            gs.addErrorMessage("Correlation ID must contain 'XYZ:INC'");
            current.setAbortAction(true);
            return; // Abort further execution
        }

        var httpStatus = response.getStatusCode();
    } catch (ex) {
        var message = ex.message;

        // Handle exceptions here if necessary

    }

})(current, previous);

'XYZ:INC' is actually 'euwbond:INC'.