JSON.stringify method is not working in service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2018 10:28 PM
Hi All,
I am getting an console error in service portal because of using
I was used this method in Script Include:
retVal = JSON.stringify(varArr);
Client script:
varsToChange = JSON.parse(answer);
Error:
PopUp Error
There is a JavaScript error in your browser console
Console error
js_includes_sp.jsx?v=05-24-2018_1317&lp=Wed_Jun_13_16_04_56_PDT_2018&c=24_309:67522 (g_env) [SCRIPT:EXEC] Error while running Client Script "Override -- None --": SyntaxError: Unexpected token u in JSON at position 0
These two methods are not working in service portal. Is any alternate method to avoid the error.
Regards,
Srikanth Suri
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2018 10:36 PM
Hi Srikanth,
In Service Portal, you are using Widgets, which is predefined to allow writing server script, client script and HTML. So you can directly call script include in Server script. If it don't work, then I think you need to write the whole code in Widget's server script.
Regards,
Manan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2018 11:13 PM
Hi,
You are sending date form script include as a string format . so JSON.prase method will not get executed, because
JSON.parse will executed when data is in JSON format you are converting that data into string.
varsToChange = JSON.parse(answer);
in that answer you get string data.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2018 11:32 PM
Hi,
just tell me your data is in JSON format ? if yes so directly send from Script include as JSON don't convert in string .
when it reaches in client script. then use JSON.parse it will definitely work.
Thanks
Gajanan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2018 11:49 PM