- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 02:39 AM
I'm creating an inbound scripted REST resource using application/json format.
I've noticed that I cannot simply do the following to create an object from the data:
var requestDataObj = JSON.parse(request.body.dataString);
return {
message: requestDataObj.number
};
If I do so, I get an HTTP 500 server error on the client-side, the following response, and error in the syslog table:
"error": {
"message": "Empty JSON string",
"detail": "SyntaxError: Empty JSON string (sys_ws_operation.7b6a102b93420210416272918bba10a8.operation_script; line 7)"
},
"status": "failure"
}
Empty JSON string: com.glide.rest.domain.ServiceException: Empty JSON string: com.glide.rest.service.custom.CustomServiceExceptionResolver.throwServiceException(CustomServiceExceptionResolver.java:82) com.glide.rest.service.custom.CustomServiceExceptionResolver.throwServiceException(CustomServiceExceptionResolver.java:77) com.glide.rest.service.custom.CustomServiceExceptionResolver.resolveForException(CustomServiceExceptionResolver.java:45) com.glide.rest.service.custom.CustomServiceResultHandler.handle(CustomServiceResultHandler.java:22) com.glide.rest.service.custom.CustomService.execute(CustomService.java:78) com.glide.rest.handler.impl.ServiceHandlerImpl.invokeService(ServiceHandlerImpl.java:37) com.glide.rest.processors.RESTAPIProcessor.process(RESTAPIProcessor.java:345) com.glide.processors.AProcessor.runProcessor(AProcessor.java:762) com.glide.processors.AProcessor.processTransaction(AProcessor.java:313) com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:187) com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:175) com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:58) com.glide.sys.Transaction.run(Transaction.java:2734) com.glide.ui.HTTPTransaction.run(HTTPTransaction.java:35) java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) java.base/java.lang.Thread.run(Thread.java:840) |
If I assign the contents of the request.body.dataString property to a variable first, everything works fine!
var requestDataString = request.body.dataString;
var requestDataObj = JSON.parse(requestDataString);
return {
message: requestDataObj.number
};
HTTP 200, Response:
{
"result": {
"message": "INC0146564"
}
}
Can anyone explain to me why this makes a difference?
I am creating all of this in a custom scope, if that makes any difference.
(All POST submissions were made using the same content, submitted via the REST API Explorer within the same instance.)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 02:59 AM
Please try
var requestDataObj = JSON.parse(String(request.body.dataString));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2025 06:03 PM - edited 06-10-2025 06:12 PM
I highly doubt that has anything to do with JS, and would look at how SN implemented it and how it's data type is set within SN's Java code for interpreting the data type. Because if the variable is named and detailed by SN as a String and it's not returned as one, then that's where the problem lies, not the language.
It should be raised as a SN defect, as it should NOT clear the 'request.body.data' object either when JSON parsing 'dataString', which it does, meaning that it's being set by reference somehow. Thus exposing the coding error on SN side.