Help Parsing a JSON String in ServiceNow Workflow Editor

appstorm
Tera Contributor

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!

1 ACCEPTED SOLUTION

Runjay Patel
Giga Sage

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

-------------------------------------------------------------------------

View solution in original post

1 REPLY 1

Runjay Patel
Giga Sage

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

-------------------------------------------------------------------------