what could be the reason for the below error??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2025 04:18 AM
The script I am using is
var latestcomment = fd_data._2__create_catalog_task.catalog_task.work_notes.getJournalEntry(1); gs.log("comment - recent work notes "); var comments = JSON.parse(latestcomment); gs.log("comment - recent work notes after parse"); for(var i=0; i<comments.length; i++){ if(comments[i]['Response']=='Reject'){ gs.log("comment - its coming to for loop "+comments[i]['Name']); var rejected_comments = comments[i]["Comments"]; gs.log("Rejected Comments are "+rejected_comments); } } return rejected_comments;
The recent comment will look like:
[{"Name":"Gopinath ","Response":"Approve","Comments":"No longer Required"}, {"Name":"Gopinath Thangamani","Response":"Reject","Comments":"Approving it for further "}]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2025 04:33 AM
@KM SN - line "var comments = JSON.parse(latestcomment);" is causing the problem as you are trying to get the j=worknotes journal entry which is not in the JSON format by default. Please parse only the comment which is expected to be JSON.
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2025 04:40 AM - edited ā03-28-2025 04:41 AM
@KM SN - You can use the below syntax to parse the journal entry which holds JSON message.
var latestcomment = fd_data._2__create_catalog_task.catalog_task.work_notes.getJournalEntry(1).split("\n")[1];
gs.log("comment - recent work notes ");
var comments = JSON.parse(latestcomment);
gs.log("comment - recent work notes after parse");
for(var i=0; i<comments.length; i++){
if(comments[i]['Response']=='Reject'){
gs.log("comment - its coming to for loop "+comments[i]['Name']);
var rejected_comments = comments[i]["Comments"];
gs.log("Rejected Comments are "+rejected_comments);
}
}
return rejected_comments;
I've added the expected JSON In worknotes and used the syntax provided above to parse the JSON
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-28-2025 04:42 AM - edited ā03-28-2025 04:43 AM
Hi @KM SN
Just modify your script as below.
var latestcomment = fd_data._2__create_catalog_task.catalog_task.work_notes.getJournalEntry(1);
gs.log("comment - recent work notes ");
//---------------------START-------------------------------
var arr = latestcomment.split("(Additional comments)\n");
var comments = JSON.parse(arr[1].toString());
//---------------------END-------------------------------
gs.log("comment - recent work notes after parse");
for(var i=0; i<comments.length; i++){
if(comments[i]['Response']=='Reject'){
gs.log("comment - its coming to for loop "+comments[i]['Name']);
var rejected_comments = comments[i]["Comments"];
gs.log("Rejected Comments are "+rejected_comments);
}
}
return rejected_comments;
Hope this helps.
Regards
Siva