How to a business rule run once?

Ibrahim Majad
Tera Expert

Hey guys I have a business rule and client script - I have it set to when there is an incident raised via portal/ desktop the user if in a member of group X will automatically be assigned to the assignment group A.

 

I do have that functionality however the problem now is that if they would like to reassign the ticket to someone else - the rule will keep running and assigning the incident to group X. 

 

Typically I would use g_form.newRecords however this doesnt work for incidents raised in the portal.

 

I am fairly new to scripting so this might be easy to fix but any help would be appreicated

business rule

IbrahimMajad_0-1670334734459.png

Client Script

IbrahimMajad_1-1670334828035.png

 

 

4 REPLIES 4

Musab Rasheed
Tera Sage
Tera Sage

Hello,

I'm not sure about your requirement but if you want to set Assignment group you can do it in BR so no need for client script, BR can run on 'Insert' and it will not work on 'Update'. check below

MusabRasheed_0-1670335274783.png

 

MusabRasheed_1-1670335305961.png

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hey @Musab Rasheed This wont work as the requirement is to only set the assignment group if they are a member of a specific group hence why I added this condition in the BR

 

g_scratchpad.membership = gs.getUser().isMemberOf('8bc1dc921b2b95d01f19848ae54bcb4b');

 

 

That's fine, since you are setting Assignment group add that in condition tab , simple, if you do with Client script then value won't be set but if you do with BR then value will be set directly then later on it can get changed.

MusabRasheed_0-1670336137807.png

Please hit like and mark my response as correct if that helps
Regards,
Musab

jaheerhattiwale
Mega Sage
Mega Sage

@Ibrahim Majad You can achieve the functionality by just creating a before (insert/update) business rule.

 

Write the following code in the new before (insert/update) business rule:

 

(function executeRule(current, previous /*null when async*/ ) {

if (gs.getUser().isMemberOf("GROUP X NAME HERE")) {
current.assignment_group = "<GROUP A SYS ID HERE>";
}

})(current, previous);

 

 

Note: Deactivate your business rule and client script

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023