- 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 10:36 PM
Hi Sai Charan
If you don't want admin to override this then uncheck 'admin override' checkbox.
Also try this 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')) && current.priority.toString()== '1') {
answer = true;
} else {
answer = false;
//gs.addErrorMessage('You dont have the right to Create/Update P1 tickets');
}
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:49 PM
Hi rohila,
Actually priority is getting read only for the users who are not part of those groups but priority is setiing up based on impact is 1 and urgency is 1 which we need to see
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-21-2022 11:04 PM
Hi Sai Charan
there are few ways you can restrict from form.
- You can write onsubmit client script and do validations here with glideajax and return false if user is not member of particular groups for p1 tickets
- write before insert/update br and abort the action if user is not member of particular groups.
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:32 PM
i have created a sys property for the groups and bought in BR,
given before business rule and insert/update and gave condaition as priority is critical
following is the code:
// (function executeRule(current, previous /*null when async*/) {
var grp1 = [];
var grp =gs.getProperty('get_groups');
grp1 =grp.split(',');
for(var k=0; k < grp1.length; k++)
{
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',current.sys_id);
gr.addQuery('assignment_group',grp1[k]);
gr.query();
if(gr.next())
{
gs.addInfoMessage('Invalid Submission for Priority 1 and Priority 2 Tickets for the Assignment Group selected');
current.setAbortAction(true);
}
}
})(current, previous