I want my business rule to run when I click on a particular UI action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 10:37 PM
I have a business rule, which must only run when I select "Complete" UI action. How can I make it happen?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 11:02 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 11:03 PM
Hi
'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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 11:10 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2021 11:35 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-28-2021 11:03 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader