- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 09:55 AM - edited 07-29-2024 09:57 AM
HI Team,
Below is sample code which is written in After Business Rule. I believe the issue is from line no 35 to line no 38 is not printing anything. I believe XML to JSON conversion is the issue.
In my try catch block I am getting error as "Unexpected Token o".
Attached is the sample code in notepad .If you see the catch block I am getting error as Unexpected Token o
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 01:05 AM
Hi @Ankur Khare
please make the below changes:
// Parse JSON string back to an object
var objHandle = JSON.parse(jsonString);
gs.log('objHandle: ' + JSON.stringify(objHandle)); // Log objHandle for debugging
// Access and log specific properties
if (objHandle.net) {
gs.log('parentNetHandle: ' + objHandle.net.parentNetHandle);
} else {
gs.log('The "net" property does not exist in the JSON object.');
}
…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution ✅!! If this helps you to understand.
…………………………………………........................................................................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 10:41 AM - edited 07-29-2024 10:41 AM
Hi @Ankur Khare ,
Can you please once try to log before parsing response.
The error "Unexpected Token o" typically occurs when JSON.parse() is trying to parse a string that is not a valid JSON. In your code, this could be happening because the gs.xmlToJSON(responseBody) function might not be returning a string that can be parsed by JSON.parse().
Here are a few things you can do to troubleshoot and fix this issue:
- Check the output of gs.xmlToJSON(responseBody): Ensure that it is indeed returning a JSON string and not some other object or string that JSON.parse cannot handle.
- Directly log the output of gs.xmlToJSON(responseBody): This will help you understand what is being returned.
Example -