- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2014 10:15 AM
Hi ServiceNow Developers,
Is there a way to get the name of the current view inside a business rule?
Please advise.
Thanks,
Johannes
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2014 06:42 AM
Since Business Rules aren't really linked to the form that submitted them there is nothing OOTB that will get you this, however it should be pretty straightforward to create something:
First create a new field/column and add it to your form and all views. Something like u_view String(40). Remember to add it to each of the views for your table.
Second create a Client Script that runs onSubit for all views (global). In the Client script you should call:
function onSubmit() {
g_form.setValue('u_view', getView());
}
getView() is a Client Side function that returns the name of the view as a string. You could also use an onLoad Client Script.
Then in your business rule current.u_view will contain the view name. Remember that the business rule might be fired by other business rules or non user/form submits and the Default View will show as an empty string "". You may also want to set the u_view field to be blank at the end of the Business Rule to avoid your code being executed when you don't want it.
Optionally you may want to create a UI Policy that hides the field from the user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2014 06:42 AM
Since Business Rules aren't really linked to the form that submitted them there is nothing OOTB that will get you this, however it should be pretty straightforward to create something:
First create a new field/column and add it to your form and all views. Something like u_view String(40). Remember to add it to each of the views for your table.
Second create a Client Script that runs onSubit for all views (global). In the Client script you should call:
function onSubmit() {
g_form.setValue('u_view', getView());
}
getView() is a Client Side function that returns the name of the view as a string. You could also use an onLoad Client Script.
Then in your business rule current.u_view will contain the view name. Remember that the business rule might be fired by other business rules or non user/form submits and the Default View will show as an empty string "". You may also want to set the u_view field to be blank at the end of the Business Rule to avoid your code being executed when you don't want it.
Optionally you may want to create a UI Policy that hides the field from the user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 06:46 AM
Fantastic answer, Andrew!
You just can't get 'view' information at the server level directly without somehow feeding the business rule from something on the client side (like Andrew posted above).
Like++!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2014 08:50 AM
Hi Andrew,
I implemented it exactly the way you explained it and it's working correctly.
Thank you very much for a great answer and for your help