Value is returning undefined in BR but returns a valid value when ran in the background script

jiral
Giga Sage

We have below BR script that returns 'undefined' when executed via BR but when tested viathe background, a valid is returned. Any idea?

 

 	var start = new GlideDateTime(gs.beginningOfToday());
	var end = new GlideDateTime(gs.endOfToday());
	var HRDataSource = '7a63d14e87459d54a0ff52083cbb3555';
	var scheduledDataImportSysId = gs.getProperty('sn_hr_core.scheduled_import_set');
    		
        var ImportSets = new GlideRecord('sys_import_set');
		ImportSets.addQuery('sys_created_on','>=',start);
		ImportSets.addQuery('sys_created_on','<=',end);     
		ImportSets.addQuery('data_source',HRDataSource);
		ImportSets.orderByDesc('sys_created_on');
		ImportSets.setLimit(1);
		ImportSets.query();
		if(ImportSets.next())
		{
			var ParentSet = ImportSets.sys_id;

			var SetParent = new GlideRecord('sys_import_set');
			SetParent.addQuery('sys_created_on','>=',start);
			SetParent.addQuery('sys_created_on','<=',end);     
			SetParent.addQuery('data_source',HRDataSource);
			SetParent.addQuery('sys_id','!=',ParentSet);
			SetParent.query();
			while(SetParent.next())
			{
				SetParent.u_parent = ParentSet;
				SetParent.update();
			}

			var errmsg;
			var error = new GlideRecord('import_log');
			error.addQuery('import_set',ParentSet);
			error.query();
			if(error.next())
			{
				errmsg = error.message;
			}

			var tcinc = new GlideRecord('incident');  
			tcinc.initialize();  
			tcinc.short_description = "HR Profiles Failed Import"; 
			tcinc.description = "Incident Automatically Created : HR Profiles  import failed with error : "  + '\n' + errmsg;;
			tcinc.assignment_group = '64e6bb2551673000fcbf74e38c66b11e'; 
			tcinc.u_caller = 'aa5d0ff8139aba400494bc122244b0ad'; 
			tcinc.u_business_service = 'b77f788c9c3d0d8072466579020b362d'; 
			tcinc.u_symptom = '270da1134f64fbc021ee7f75f110c7fc'; 
			tcinc.insert();
        }

 The particular part returning undefined via BR is the errmsg. 

2 REPLIES 2

Amit Verma
Kilo Patron
Kilo Patron

Hi @jiral 

 

Have you tried debugging the Business rule via Debugger ? Also, can you check on the table "import_log", you are able to find the record you are querying via Parent Set by applying manual filters on the list.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

There's nothing showing up in the BR Debugger for the BR(in sys_import_set_run table) in question for the import_log. Manual query on the import_log for the ParentSet worked and it returned the record and the value.

			var errmsg;
			var error = new GlideRecord('import_log');
			error.addQuery('import_set',ParentSet);
			error.query();
			if(error.next())
			{
				errmsg = error.message;
			}