- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 02:04 AM - edited 10-31-2023 02:16 AM
Hi all,
I am trying to fetch 'expected target date' and 'Top affected orgknot' in notification but it is coming as undefined can you pls tell me, i tried with "JSON.stringify(obj)" and also without it but still not working please check.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 02:30 AM
@Prathamesh Cha1 Update your script as follows.
var obj = {};
var gr = new GlideRecord('sn_hr_core_case_workforce_admin');
gr.addQuery('sys_id', 'cb4ff94c1b9a31d01eeafc07cb4bcb0c');
gr.query();
while(gr.next())
{
obj = JSON.parse(gr.payload); //parse the JSON here.
gs.print(obj.expected_target_date);
}
gs.print(gr.payload.expected_target_date)
var payload = {"expected_target_date":"2023-11-14","opened_for":"023894189726a1907ecb7a500153af0b","subject_person":"e55baca5db47e110e37999fbd396193c","top_affected_orgknot":"b619537d1b1d71901eeafc07cb4bcb2b","what_do_you_want_to_change":"fd486951db6f6190e37999fbd3961927"}
gs.print(payload.expected_target_date);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 02:30 AM
@Prathamesh Cha1 Update your script as follows.
var obj = {};
var gr = new GlideRecord('sn_hr_core_case_workforce_admin');
gr.addQuery('sys_id', 'cb4ff94c1b9a31d01eeafc07cb4bcb0c');
gr.query();
while(gr.next())
{
obj = JSON.parse(gr.payload); //parse the JSON here.
gs.print(obj.expected_target_date);
}
gs.print(gr.payload.expected_target_date)
var payload = {"expected_target_date":"2023-11-14","opened_for":"023894189726a1907ecb7a500153af0b","subject_person":"e55baca5db47e110e37999fbd396193c","top_affected_orgknot":"b619537d1b1d71901eeafc07cb4bcb2b","what_do_you_want_to_change":"fd486951db6f6190e37999fbd3961927"}
gs.print(payload.expected_target_date);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 02:32 AM
you cannot directly parse the json object by simply using GlideRecord object
you need to store the value in a variable and then parse the json object
this should work for you
var gr = new GlideRecord('sn_hr_core_case_workforce_admin');
gr.addQuery('sys_id', 'cb4ff94c1b9a31d01eeafc07cb4bcb0c');
gr.query();
if (gr.next()) {
var obj = {};
obj = gr.payload;
gs.info(obj.expected_target_date);
var payload = {
"expected_target_date": "2023-11-14",
"opened_for": "023894189726a1907ecb7a500153af0b",
"subject_person": "e55baca5db47e110e37999fbd396193c",
"top_affected_orgknot": "b619537d1b1d71901eeafc07cb4bcb2b",
"what_do_you_want_to_change": "fd486951db6f6190e37999fbd3961927"
}
gs.info(payload.expected_target_date);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader