Notifications

14 views

Business Rule "Validate operational work type"


This Business Rule is installed with the plugin "Resource Management" [ com.snc.resource_management ] and on Kingston release and earlier releases the Script part of the business rule has one issue.

The business rule if installed OOTB or by plugin installation will have a sys_id = "bd8c14d89390320064f572edb67ffbd9".

 

The Script and how to fix it


On London release and earlier releases the Script that the business rule runs is as follow:

 

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

var opWorkType = current.getValue('operational_work_type');
var gr = new GlideRecord('sys_choice');
gr.addQuery('table', 'time_card');
gr.addQuery('element', 'category');
gr.addQuery('value', opWorkType);
gr.setLimit(1);
gr.query();

if (gr.getRowCount() < 1) {
gs.addErrorMessage(gs.getMessage('The selected operational work type is not a valid category in time cards. Contact System Administrator to add it as a choice for time card category.'));
current.setAbortAction(true);
}

})(current, previous);

 

 

In the line 5 of the code we read "gr.addQuery('table', 'time_card');", however, this is a GlideRecord object configured to access the table "sys_choice", and the table "sys_choice" doesn't have a field called "table", it has, however, a field called "name", and this is the field with type "Table Name":

 

 

To fix the script code we must change the line number 5 and make it query the name field:

"gr.addQuery('name', 'time_card');"

The code will look like this: 

 

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

var opWorkType = current.getValue('operational_work_type');
var gr = new GlideRecord('sys_choice');
gr.addQuery('name', 'time_card');
gr.addQuery('element', 'category');
gr.addQuery('value', opWorkType);
gr.setLimit(1);
gr.query();

if (gr.getRowCount() < 1) {
gs.addErrorMessage(gs.getMessage('The selected operational work type is not a valid category in time cards. Contact System Administrator to add it as a choice for time card category.'));
current.setAbortAction(true);
}

})(current, previous);

 

This issue impact instances running the London release or earlier releases, future instances on Madrid release should get the correct Business Rule.

In the future if your instance has been upgraded from London to Madrid and the script does not look correct, please check the Upgrade History to certify the Business Rule was not installed (a.k.a. Skipped) because it collided with the existing version which might have been modified by admins.

Article Information

Last Updated:2018-11-06 09:41:00
Published:2018-11-06