- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 10:18 PM
Hi can anyone help me with the help for the code i have written
i want to restrict the p1 incident for selecting for the groups except the groups which i have written in the code, whats happening is that i have clicked on admin over rides and even i can see the error message. here is the following code :
if(gs.getUser().isMemberOf('9d0a216a0a0a3caa0115b93dfaf2ae56')||gs.getUser().isMemberOf('a0cc6d93db123340d8837fc88c96196e')||gs.getUser().isMemberOf('9d0a20990a0a3caa003f7be11bb58e93')||gs.getUser().isMemberOf('9d0a21960a0a3caa00e62aec0c92ba7f')||gs.getUser().isMemberOf('fc8122092dad344433e3a12e0d26d3bf')||gs.getUser().isMemberOf('1bc9942b394a5ec033e3e16ef1a2ae33')||gs.getUser().isMemberOf('de363e537d886d40fbb6296def8c2cf6')&¤t.priority == '1')
{
answer = true;
}
else{
answer = false;
gs.addErrorMessage('You dont have the right to Create/Update P1 tickets');
}
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 11:39 PM
You don't need to query the incident table. I believe the Before insert/update BR is on incident table and you need to check whether the logged in user is part of the groups or not like below:
(function executeRule(current, previous /*null when async*/ ) { if ((gs.getUser().isMemberOf('9d0a216a0a0a3caa0115b93dfaf2ae56') || gs.getUser().isMemberOf('a0cc6d93db123340d8837fc88c96196e') || gs.getUser().isMemberOf('9d0a20990a0a3caa003f7be11bb58e93') || gs.getUser().isMemberOf('9d0a21960a0a3caa00e62aec0c92ba7f') || gs.getUser().isMemberOf('fc8122092dad344433e3a12e0d26d3bf') || gs.getUser().isMemberOf('1bc9942b394a5ec033e3e16ef1a2ae33') || gs.getUser().isMemberOf('de363e537d886d40fbb6296def8c2cf6')) && current.priority.toString() == '1') { //do nothing } else { gs.addErrorMessage('You dont have the right to Create/Update P1 tickets'); current.setAbortAction(true); } })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 01:44 AM
Hi @sai charan7
If the values are stored in a property then you can simply use below logic in 'Before Insert BR'
(function executeRule(current, previous /*null when async*/ ) {
var isMember = false;
var grp = gs.getProperty('get_groups').split(",");
for (var x = 0; x < grp.length; x++) {
isMember = gs.getUser().isMemberOf(grp[x]);
}
if (!isMember) {
gs.addErrorMessage('You dont have the right to Create/Update P1 tickets');
current.setAbortAction(true);
}
})(current, previous);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 11:39 PM
You don't need to query the incident table. I believe the Before insert/update BR is on incident table and you need to check whether the logged in user is part of the groups or not like below:
(function executeRule(current, previous /*null when async*/ ) { if ((gs.getUser().isMemberOf('9d0a216a0a0a3caa0115b93dfaf2ae56') || gs.getUser().isMemberOf('a0cc6d93db123340d8837fc88c96196e') || gs.getUser().isMemberOf('9d0a20990a0a3caa003f7be11bb58e93') || gs.getUser().isMemberOf('9d0a21960a0a3caa00e62aec0c92ba7f') || gs.getUser().isMemberOf('fc8122092dad344433e3a12e0d26d3bf') || gs.getUser().isMemberOf('1bc9942b394a5ec033e3e16ef1a2ae33') || gs.getUser().isMemberOf('de363e537d886d40fbb6296def8c2cf6')) && current.priority.toString() == '1') { //do nothing } else { gs.addErrorMessage('You dont have the right to Create/Update P1 tickets'); current.setAbortAction(true); } })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 11:34 PM
Try this
Before insert br
(function executeRule(current, previous /*null when async*/ ) {
if ((gs.getUser().isMemberOf('9d0a216a0a0a3caa0115b93dfaf2ae56') || gs.getUser().isMemberOf('a0cc6d93db123340d8837fc88c96196e') || gs.getUser().isMemberOf('9d0a20990a0a3caa003f7be11bb58e93') || gs.getUser().isMemberOf('9d0a21960a0a3caa00e62aec0c92ba7f') || gs.getUser().isMemberOf('fc8122092dad344433e3a12e0d26d3bf') || gs.getUser().isMemberOf('1bc9942b394a5ec033e3e16ef1a2ae33') || gs.getUser().isMemberOf('de363e537d886d40fbb6296def8c2cf6')) && current.priority.toString() == '1') {
//do nothing
} else {
gs.addErrorMessage('You dont have the right to Create/Update P1 tickets');
current.setAbortAction(true);
}
})(current, previous);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 01:44 AM
Hi @sai charan7
If the values are stored in a property then you can simply use below logic in 'Before Insert BR'
(function executeRule(current, previous /*null when async*/ ) {
var isMember = false;
var grp = gs.getProperty('get_groups').split(",");
for (var x = 0; x < grp.length; x++) {
isMember = gs.getUser().isMemberOf(grp[x]);
}
if (!isMember) {
gs.addErrorMessage('You dont have the right to Create/Update P1 tickets');
current.setAbortAction(true);
}
})(current, previous);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 10:55 PM
Hi @sai charan7 , Which level of ACL is this? do you want the admins to be able to update the P1's?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 10:56 PM
yes admin and the sys id of groups only need to see p1 option