JSON Parse not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 08:25 AM
HI Team,
We have written a script include which is Global scope and also Before BR also in same scope
We are calling the script include as below
var parseValue = JSON.parse(new CustomerAccountUtil().getRootParent(current.sys_id));
But on doing gs.addInfoMessage(parseValue );
Its giving undefined message/error. However at script include side when we do gs.log() we are getting the proper output.
Kindly help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 08:47 AM
@Community Alums Could you please check if new CustomerAccountUtil().getRootParent(current.sys_id)) a valid JSON string? If it isn't than you can expect to have errors while using JSON.parse method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 08:49 AM
We are passing JSON object from script include and getting undefined error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 08:51 AM - edited 11-13-2023 08:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 09:00 AM - edited 11-13-2023 09:06 AM
@Community Alums try this
getRootParent: function(rec) {
var obj = {};
var objSysId = [];
var retValue = '';
var record = new GlideRecord('customer_account');
record.addQuery('sys_id', rec);
record.query();
if (record.next()) {
if (record.account_parent.toString() == '') {
obj.sysId = record.getValue('sys_id');
obj.custAcct = record.getValue('account_path');
objSysId.push(obj);
gs.log("My array objstysid: "+objSysId);
return JSON.stringify(objSysId);
} else {
this.getRootParent(record.account_parent.toString());
}
}
return "";
},
var answer= new CustomerAccountUtil().getRootParent(current.sys_id);
gs.addInfoMessage(answer);
answer = JSON.parse(answer);
gs.addInfoMessage(answer);
Validate the log added in the script include if you still not getting the values on BR.
Thanks!
Please mark it as correct and helpful if it works✔️👍
