Run Business Rule only once

Geeky
Kilo Guru

I have a requirement to run the business rule logic only once based on a flag. Initially flag will be null and once it its set, business rule should run and when user tried to modify the record again, business rule should not run.

1 ACCEPTED SOLUTION

Ankit P
Mega Guru

As I am not sure of your exact requirement below are the possibilities:

1. Run the BR only on Insert if that needs to be run only on new records.

2. If BR needs to be run only if the flag changes from null, then you can choose the filter "changes from" condition.

3. If both of them doesn't fulfill your requirement, you can make the BR inactive after first run. Below is the script:

// perform your actions first
//e.g.

  gs.addInfoMessage("This message will only show once for this record.");
	
//make this BR inactive
	var gr = new GlideRecord('sys_script');
	gr.get('sys_id of the Business Rule');
	gr.active = false;
	gr.update();

View solution in original post

8 REPLIES 8

Bhagya Lakshmi
Mega Guru

You can write business rule and in the script

You can write like

if(flag=="")

{

write your script

}

else

{

current.setActionAbort(true);

}

 

Thanks.

This would abort the DB action every time after the flag is set to true. 

It would work I guess, only else part needs to be removed.

Ankit P
Mega Guru

As I am not sure of your exact requirement below are the possibilities:

1. Run the BR only on Insert if that needs to be run only on new records.

2. If BR needs to be run only if the flag changes from null, then you can choose the filter "changes from" condition.

3. If both of them doesn't fulfill your requirement, you can make the BR inactive after first run. Below is the script:

// perform your actions first
//e.g.

  gs.addInfoMessage("This message will only show once for this record.");
	
//make this BR inactive
	var gr = new GlideRecord('sys_script');
	gr.get('sys_id of the Business Rule');
	gr.active = false;
	gr.update();