Optimize the below Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 11:40 PM - edited 05-27-2024 12:34 AM
Hi All ,
I want to optimize the below Business rule , I have two business rules which use the below highlighted code :
I want to create a script include for this part of code and then call the function in the condition of the business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 12:14 AM
Hi @Pooja Khatri ,
Please try the below:
Script Include
var UserUtils = Class.create();
UserUtils.prototype = {
initialize: function() {
},
isWebServiceUser: function(userId) {
var user = new GlideRecord('sys_user');
if (user.get(userId)) {
return user.web_service_access_only == true;
}
return false;
},
type: 'UserUtils'
};
Business rule:
(function executeRule(current, previous /null when async/) {
var userUtils = new UserUtils();
var isWebServiceUser = userUtils.isWebServiceUser(gs.getUserID());
if (gs.nil(current.work_notes)) {
if (!gs.getSession().isInteractive() && isWebServiceUser) {
gs.addErrorMessage('Work notes are mandatory');
current.setAbortAction(true);
return;
}
}
if (current.impact == 1 && current.urgency == 1) {
if (!gs.getSession().isInteractive() && isWebServiceUser) {
gs.addErrorMessage("Cannot be High simultaneously.");
current.setAbortAction(true);
return;
}
}
})(current, previous);
Please consider marking my reply as Helpful and/or Accept Solution, if it helps. Thanks!
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 02:25 AM
Hi @Pooja Khatri ,
Try below:
Script Include:
var UserUtils = Class.create();
UserUtils.prototype = {
initialize: function() {},
isWebServiceAccessOnly: function(userId) {
var user = new GlideRecord('sys_user');
if (user.get(userId)) {
return user.web_service_access_only == true;
}
return false;
},
type: 'UserUtils'
};
In Business rule, Replace the code provided by you with below code:
if (new UserUtils().isWebServiceAccessOnly(gs.getUserID())) {
// Your existing business rule logic
}
If you find my response helpful, please consider selecting "Accept as Solution" and "Helpful" .
Thanks,
Anusha