Use parameter for glide record query in script include - Not working

Andrew Bettcher
Kilo Sage

This is so weird and I need help before I drive myself insance.

I'm calling a script include from a business rule:

Before Insert:

(function executeRule(current, previous /*null when async*/ ) {

var sysID = current.sys_id;
var callIt = new inboundAutomation(); //inboundAutomation script include
callIt.inboundAutoFunc(sysID); //inboundAutoFunc function (and pass the current sys ID)

})(current, previous);

According to info statements, it works. The sys_id is passed over. I then use that sys_id to do a glide record query but I don't get a result:

var inboundAutomation = Class.create();
inboundAutomation.prototype = {
    initialize: function() {
    },
	
	inboundAutoFunc: function(sysID){		
	gs.info('xyz1: ' + sysID);
	var inc = new GlideRecord('incident');
	inc.addQuery('sys_id', sysID);
	inc.query();

	while(inc.next()){	
	
	var incNum = inc.number;
	gs.info('xyz2 - Number' + incNum);

	var incDesc = inc.short_description;
	}
	},
		
    type: 'inboundAutomation'
};

If I use an absolute value in the query then it works OK. It only fails when trying to use the sysID variable passed from the BR...And, whilst I typed this I wondered if the business rule being set to "Before" was an issue. There may be no way for the query to run until the record is committed to the database.....

1 ACCEPTED SOLUTION

Andrew Bettcher
Kilo Sage

Changed BR to After and it worked. D'oh.

View solution in original post

2 REPLIES 2

Andrew Bettcher
Kilo Sage

Changed BR to After and it worked. D'oh.

Hi Andrew, 

Or use .getUniqueValue() instead of sys_id.

current.getUniqueValue();

If there is a need to abort business rule, better to keep it as "before".