- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 08:02 PM
I am trying to pass the JSON Request from the scripted REST API using the POST method to a script Include for further validations.
I have tried with the logs but the script include is not being triggered with the request.
Scripted REST API:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var body = request.body.data;
var strBody = JSON.stringify(body);
var ship = shipmentInsertionvalidations.ws_createShipments(strBody);
gs.info(ship);
return ship;
})(request, response);
Script Include
var shipmentInsertionvalidations = Class.create();
shipmentInsertionvalidations.prototype = {
initialize: function() {
this.error_message = String();
},
ws_createShipments: function(wp_request){
gs.info("LOG_SHIP"+wp_request);
},
type: 'shipmentInsertionvalidations'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 08:32 PM - edited ‎09-20-2023 08:37 PM
Can you try updating below line in your code.
Scripted Rest api :
var ship = new shipmentInsertionvalidations().ws_createShipments(strBody);
and in script include:
var shipmentInsertionvalidations = Class.create(); shipmentInsertionvalidations.prototype = { initialize: function() { this.error_message = String(); },
ws_createShipments: function(wp_request){
gs.info("LOG_SHIP"+wp_request);
return "something";
},
type: 'shipmentInsertionvalidations'
};
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2023 08:32 PM - edited ‎09-20-2023 08:37 PM
Can you try updating below line in your code.
Scripted Rest api :
var ship = new shipmentInsertionvalidations().ws_createShipments(strBody);
and in script include:
var shipmentInsertionvalidations = Class.create(); shipmentInsertionvalidations.prototype = { initialize: function() { this.error_message = String(); },
ws_createShipments: function(wp_request){
gs.info("LOG_SHIP"+wp_request);
return "something";
},
type: 'shipmentInsertionvalidations'
};
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 12:26 AM
Thanks for the response!!
I am trying to the response back from the script include as below. But it doesn't works. Could you pls help me out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2023 01:00 AM
Refer the below script , you can adjust your code accordingly
try{
var ship = new shipmentInsertionvalidations().ws_createShipments(strBody);
var resp = {};
resp ["value"]= ship;
response.setBody(JSON.stringify(resp));
}
catch(ex){
// in case of error
var resp = {};
resp ["status"] = "Error Message";
resp ["message"] = ex.message;
response.setBody(JSON.stringify(resp ));
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates