JSON.stringify method is not working in service portal

Srikanth Suri1
Kilo Expert

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

 

 

4 REPLIES 4

Manan Raval
Giga Expert

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

Gajanan Birada1
Giga Expert

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.

Gajanan Birada1
Giga Expert

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

RAHUL Khanna1
Mega Guru
Hi Srikanth ,your data might not be in JSON format. Please paste your content here,