Prevent tag submission

Momiji
Tera Contributor

I have a tag called "Tag Ex" and only specific groups are allowed to use this. I have created a before business rule so that an error appears when a user outside the groups tries to apply the tag with the same name. It will still allow outside users to submit the tag but when refreshing the record, the tag was not really saved. As what I have read (I'm not sure if this is true), Business Rule only fires after the user already tries to add the tag. So maybe that's why it still allows the user to submit the tag. What I want to happen is to really prevent submission.

 

Thanks!

5 REPLIES 5

Ankur Bawiskar
Tera Patron

@Momiji 

you can try to add the group to whom it should be viewable from here

add the groups you want so only members of those groups can see

I haven't tried this approach

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thanks for your response. I have already configured this part here. If I didn't create a BR, it will create the same tag name and the system appends [private] to the name. 

Naveen20
ServiceNow Employee

Use a Before Business Rule on label_entry (Insert) with setAbortAction(true) — that's the key piece you're likely missing:

(function executeRule(current, previous) {
    if (current.label.name != 'Tag Ex')
        return;

    var allowedGroup = 'Your Group Name';
    if (!gs.getUser().isMemberOf(allowedGroup)) {
        current.setAbortAction(true);
        gs.addErrorMessage('You do not have permission to apply the "Tag Ex" tag.');
    }
})(current, previous);

Without setAbortAction(true), your BR only shows a message but still lets the insert go through. This single line is what actually prevents the record from being saved. The user will still see the tag appear momentarily in the UI (since the tag widget adds it client-side optimistically), but on the server the insert is fully blocked — on refresh, the tag won't be there and the error message will display.

If you want to eliminate even that brief visual flicker, pair this with a Create ACL on label_entry using the same group check — ACLs are enforced earlier in the request lifecycle and give a tighter prevention. But setAbortAction(true) alone solves the core problem of the tag actually saving.

Momiji
Tera Contributor

Hi @Naveen20,

Thanks for your response. setAbortAction(true) is already present in my BR and it still allowed to submit tag. But like I said, when the record is refreshed, the tag was not really saved 😅