I want my business rule to run when I click on a particular UI action.

Bharath K B3
Tera Contributor

I have a business rule, which must only run when I select "Complete" UI action. How can I make it happen?

9 REPLIES 9

Mukesh24
Kilo Guru

If you fire an event from your UI Action, you can trigger the Script Actions (sysevent_script_action) from the event but you cannot trigger a Business rule. The Script Actions runs on server-side so should be able to do the same what a Business rule does.

Rekha Esadkar
Tera Expert

Hi @author ,

 

'Before' business rules always run before the record is actually saved to the database.  If you want to move the business rule code into the UI action you can do that using this SNGuru solution.

https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

 

or

Instead of writing a business rule and wanting it to run from the UI Action, you could either move the business rule code to the UI Action or instead put all the business rule code in a script include and call the script include from the UI Action (a better solution).

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Bharath K B 

So are you saying your want your BR to run only when "Complete" UI Action is clicked and record is saved.

But not when any other UI action is updating the record.

BR script won't know record got updated from which UI action unless you set some field with some value.

What field is updated from "Complete" UI Action.

Give that condition in your BR which want to run

Regards
Ankur

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

@Bharath K B 

you can try this in your BR script and check if it prints the UI action name

var actionName = action.getActionName();

If this works then in the other BR add this condition so that other BRs don't run for other UI actions

action.getActionName() != 'complete'

Regards
Ankur

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

@Bharath K B 

Hope you are doing good.

Did my reply answer your question?

Would you mind marking the best matching answer as correct and helpful, to close this thread?

Regards
Ankur

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