Server script help for outbound call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 12:05 AM
Hi,
I have below requirement.
we have a custom table and we are integrating with third party system.
When state is Pending for Int then we are triggering the below assync BR.
try {
var access_Token = new global.myIntegrationUtils().getAccessToken('sys_ of oauth', 'name of Application registry');
var r = new sn_ws.RESTMessageV2('restmessage_name', 'RESTMESSAGE');
r.setRequestHeader('Authorization', 'Bearer ' + access_Token);
r.setStringParameterNoEscape('emp_id', current.getValue("employee_number"));
r.setStringParameterNoEscape('my_id_number', current.getValue("id_number"));
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
responseBody = typeof responseBody == "string" ? responseBody : JSON.stringify(responseBody);
var SAPresposneToUpdate = httpStatus == 201 ? gs.getMessage('Successfully updated in SAP \n {0}', [responseBody]) : responseBody;
current.work_notes = SAPresposneToUpdate;
if (httpStatus == 201 || httpStatus == 200) {
current.state = 3; // if Success = closing request
gs.eventQueue('notigy_requestor', current, '');
} else {
// if there is any error we need to retrigger
state= 5; // this will be moving to retrigger state
current.id_number = ''; //setting blank to this field
gs.eventQueue('notigy_grmember', current, '');
}
current.update();
} catch (ex) {
var message = ex.message;
}
I am not understanding how to retrigger the Business rule and handle the errors.
errors can be as below:
employee number locked = we will get status code = 400
if we give same id number for 2 request = we will status code= 400
we need to correct this and retrigger.
Please help me if anyone have any idea how to handle error codes and retrigger my Outbound integration.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 12:18 AM
Hi Kaveri, the httpsStatus variable contains response status. we can use the variable the check the status is 400 or not. Please try it.
var httpStatus = response.getStatusCode();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 12:21 AM
Hi Kaveri, Please try using httpStatus variable. It contains status of the response.
var httpStatus = response.getStatusCode();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 12:21 AM
Hi Kaveri, Please try using httpStatus variable. It contains status of the response.
var httpStatus = response.getStatusCode();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 01:13 AM
Hi @Are Kaveri
Can you please confirm on this point - We need to correct this and trigger ? Who will correct it ? Whether it will be auto corrected or it's a manual update ?
Do you want to make the REST API call again if you get status code as 400 ? If yes, you can make a function to call your REST API code and call it recursively. You can put a condition that until you don't get the status code as 200, it should try. Please note that you might end up creating an endless loop so you should restrict these calls with maximum number of retry flag.
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.