- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:59 AM
Am trying below script as Custom Action script as #step 5 below in Flow Designer as part of a subflow.
(function execute(inputs, outputs) {
// ... code ...
var JS_N = new GlideRecord('checklist_template');
//JS_N.get('4d34b3c1932402101ad330dcebba10ed');
JS_N.get(inputs.checklist_template_id);
checklistArr = JSON.parse(JS_N.getValue('template'));
// Delay of 10 seconds
var seconds = parseInt(10, 10) * 1000;
var start = parseInt(new Date().getTime()) + seconds;
while(start>parseInt(new Date().getTime())){
// do nothing
}
outputs.owner = checklistArr['owner'];
//outputs.owner = inputs.checklist_template_id;
//Create checklist object
var chk = new GlideRecord('checklist');
chk.initialize();
chk.setValue('owner', checklistArr['owner']); //-----------> this lookup fails
chk.setValue('table', 'sc_task');
//chk.setValue('document', '2d47bb5393a002101ad330dcebba102f');
chk.setValue('document', inputs.sc_task_record_id);
chk.setValue('name', checklistArr['name']);
var checklistId = chk.insert();
//Loop through template and create checklist
for(var key in checklistArr.items)
{
var chki = new GlideRecord('checklist_item');
chki.initialize();
chki.setValue('checklist', checklistId);
chki.setValue('name', checklistArr.items[key]['name']);
chki.setValue('order', checklistArr.items[key]['order']);
outputs.name = chki.getValue('name');
chki.insert();
}
})(inputs, outputs);
Script fails with this error.
Error: Cannot read property "owner" from null, Detail: Cannot read property "owner" from null
Even the delay of 10 seconds I have introduced didn't help resolve the error. As such the script works as expected if tested as standalone.
Please advise.?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 01:53 PM
Hi, if you are using gs.info() or gs.log() you should find the output in system logs.
If you are unsure about logging working as expected, then perhaps also add plain text logging before you try to log your JSON payload - just to confirm the script\flow is running and logging.
System Logs > System Log > All
/syslog_list.do?sysparm_query=sys_created_onONToday%40javascript%3Ags.daysAgoStart(0)%40javascript%3Ags.daysAgoEnd(0)&sysparm_view=
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 12:16 PM
Hi, if the flow is in a scoped app then you need to instantiate 'JSON' using global.JSON,
otherwise with no clear details of your payload it's not possible for the community to evaluate possible issues.
What output do you see if you log your JSON payload? something like this should do it
gs.info(global.JSON.stringify(checkListArr));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 12:46 PM
Hi @Tony Chatfield1 Thanks for your reply. Flow is not in scoped app. I tried running with your suggestion to add global.JSON call, but I don't see any difference in output. logging using gs.log doesn't return anything in the output. Is there a place to check these logs.?
Please suggest what other data you wanted to look so I can share the same. Thanks for reviewing my question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 01:53 PM
Hi, if you are using gs.info() or gs.log() you should find the output in system logs.
If you are unsure about logging working as expected, then perhaps also add plain text logging before you try to log your JSON payload - just to confirm the script\flow is running and logging.
System Logs > System Log > All
/syslog_list.do?sysparm_query=sys_created_onONToday%40javascript%3Ags.daysAgoStart(0)%40javascript%3Ags.daysAgoEnd(0)&sysparm_view=
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 02:52 PM
Thanks @Tony Chatfield1 It is very helpful. I could resolve the issue by correcting input value set to the query. I have to change from GlideRecord object to Sys_id when getting the specific record.