Error failing to retrieve owner information from custom action script

Sri29
Tera Contributor

 

Am trying below script as Custom Action script as #step 5 below in Flow Designer as part of a subflow.

 

1. Create Request Record
2. Create Requested Item Record
3. Create Catalog Task Record
4. Look Up Checklist Template Record where (Name is myChkLstTmpl)
5. Convert JSON string to Complex Object

 

(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.?

1 ACCEPTED SOLUTION

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=

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

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));

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.

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=

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.