Current value not returning in Business Rule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 03:19 AM
Please could someone take a look over my script that ive written and help me out?
(function executeRule(current, previous /*null when async*/ ) {
var user = gs.getUserID();
var contact = current.contact;
gs.info('MIIA User ID: ' + user);
gs.info('MIIA Current Contact: ' + contact);
if (contact == user) {
gs.info('MIIA User is the contact.');
return;
} else {
var grUser = new GlideRecord('customer_contact');
if (grUser.get(user)) {
var userHelpCentreProfile = grUser.getValue('u_help_centre_profile');
gs.info('MIIA User Help Centre Profile: ' + userHelpCentreProfile);
if (userHelpCentreProfile == '3') {
current.addQuery('sys_class_name', '!=', 'sn_customerservice_case');
gs.info('MIIA Query added to hide the record.');
}
}
}
})(current, previous);
I am trying to allow a user to view the tickets that they raise and are the contact, but then if not the contact, then to exclude a certain class.
The log returns no value when i log in as the user and create the ticket:
MIIA Current Contact: |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 10:27 AM
I don't know that I'm exactly following that - I'm sure it will make sense tomorrow. With what I caught it seems like you can follow what the BR is doing, but add different logic for 1 and 2? Upon looking at my script again, I see it would be better to get the profile once, then go into the case GR, so something more like this:
(function executeRule(current, previous /*null when async*/ ) {
var caseArr = [];
var user = gs.getUserID();
//gs.info('MIIA User ID: ' + user);
var grUser = new GlideRecord('customer_contact');
if (grUser.get(user)) {
var userHelpCentreProfile = grUser.getValue('u_help_centre_profile');
gs.info('MIIA User Help Centre Profile: ' + userHelpCentreProfile);
}
var caseGr = new GlideRecord('sn_customerservice_case');
caseGr.query();
while (caseGr.next()) {
if (userHelpCentreProfile == '1') {
//do something
} else if (userHelpCentreProfile == '2') {
//do something else
}
else if (userHelpCentreProfile == '3') {
if (caseGr.contact == user) {
gs.info('MIIA User is the contact.');
caseArr.push(caseGr.sys_id.toString());
gs.info('MIIA case added to list.' + caseGr.number);
}
}
}
current.addQuery('sys_id', 'IN', caseArr.join(','));
})(current, previous);
where you would also push the cases to the array if whatever criteria for 1 and 2 are met - or always if that works. You might also need to incorporate standard/admin since this BR will run for everyone - if it turns out that admins are missing some cases.