Abort Submission when correlation ID does not contain 'xyz'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 03:08 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 03:23 AM
I'm puzzled. The code is doing what you are asking it to do. It is doing what you described you want it to do as well. What are the conditions for the business rule? Is it on Update or on Insert or both? And is the business rule before or after action ? For me this doesn't look like a code issue, rather a wrong trigger might be used..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 03:29 AM - edited 03-25-2024 03:36 AM
BR runs on below condition,
Before , Insert & update.
Script isn't aborting.
I want to abort if received correlation id does not contains "XYZ:INC".('euwbond:INC')
But it actually sets the new value , 123:INC.
It should only set 'euwbond:INC12345'. not '123:INC123'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 05:57 AM
Based on the pictures you sent, the insert is prevented. Can you please validate that the incident isn't created? Is it possible that you still see the value because it's cached in the UI Form? How exactly are you testing this code? Another thing which I would recommend is to have printing from ALL possible outcomes, including the error one. With the snippet you shared, in case the business logic fails with some error, you would never know it failed, nor why it failed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 06:45 AM
As per BR conditions, There are few groups which are supported by Y company.
When BR conditions are satisfied. Ticket is created on Y company & correation ID is received.
I have set a pre-fix called 'euwbond:INC' to understand if it's coming from Y company.
Just to test else part of my correlation_id alert msgs. I have changed the pre-fix to '123:INC'
I'm successfully receving the else part error message but '123:INC' is still getting set on correlation_id.
I want to abort this.
Ex:- If received correlation_id does not contain'euwbond:INC' ,then do not store the value on correlation_id.
Abort it.
But my script isn't doing it. It gives error msg(invalid insert) but accepting & storing on correlation_id.
Not sure how to do error handling mentioned by you. Can you please guide me step-step if possible.