- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 08:17 AM
When trying to parse a JSON string from the course_information field on a requested item, the IF statement errors out on the workflow.
{"PTRM_CODE":"81X","SUBJ_CODE":"HIMT","CRSE_NUMB":"101","SEQ_NUMB":"10P"}
// Parse the JSON string in the course_information field
var courseInfo;
try {
courseInfo = JSON.parse(current.course_information);
} catch (e) {
// Handle parsing error (if needed)
return false; // or log the error
}
// Check if PTRM_CODE is "81X"
if (courseInfo.PTRM_CODE === '81X') {
return true;
} else {
return false;
}
I'm guessing this is something to do with the JSON string, itself, because the course_information field is returning null or undefined. Any help is appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 08:25 AM
Hi @appstorm ,
check this thread, it will help you.
https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166
Server side code will work in workflow editor.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 08:25 AM
Hi @appstorm ,
check this thread, it will help you.
https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166
Server side code will work in workflow editor.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------