
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 08:19 AM
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.....
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 08:20 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-27-2022 08:20 AM
Changed BR to After and it worked. D'oh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2022 09:56 PM
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".