- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2015 02:33 PM
Hello Community,
I'm working on a form and I'm interesting in creating different views depending on who is viewing the form. I've managed to create a view but it's not giving me the functionality I'd hoped for.
To create the view, I right-clicked the banner > personalize > Form Layout and created the new view(test_view);
I am aware of the 'View Rules' that should determine when to enforce the view. The problem with this is that the View Rules don't allow for Scripted conditions. That's what I am looking for. I need to modify the view of the form based on role. I thought I had gotten lucky when I saw the 'Roles' option on the UI View form but that didn't appear to do anything.
I have tried using an onLoad Client Script to determine the view as well. If the view is NOT already set for 'test_view', this value comes back null. How could I use this to change the view if it is null? I've tried using the switchView() function which has terrible performance but actually does work.
function onLoad() {
//Type appropriate comment here, and begin script below
var thisView = document.getElementById('sysparm_view').value;
alert("Current View: " + thisView);
}
I have also tried a 'Display' Business Rule with the GlideTransaction method..
var transaction = GlideTransaction.get();
var ViewName = transaction.getRequestParameter("sysparm_view");
gs.log(ViewName);
This produced the same results as the client script. If the view is already set as 'test_view', it returns that value. Otherwise, it returns null. I'm guessing the 'default' view doesn't have a value? I also tried using the getPageName() function i found in another post but that did nothing.
My goal is to change the view of the form(and list view if possible) based on the current logged in user having a certain role. Any help is greatly appreciated.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2015 08:44 AM
Hey Kenneth,
This format is the replacement for the global business rule. One thing to note is that your script include name has to be identical to your function name.
Use Script Includes Instead of Global Business Rules
I tested this on a Eureka instance but it should work on previous versions. I hope that helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2015 03:18 PM
Hey Kenneth,
This isn't a direct answer to your question by you can setup the equivalent of a dynamic view rule. You can put your script conditions in a script include function and then call that as one of the conditions in the view rule.
View Rule (second condition is "javascript:dynamicViewRule()")
In this case the "active is true" condition isn't needed. You could do all your conditions in the script or as a combination of conditions from the condtion builder and the dynamic script. The view rule javascript has access to current so you can evaluate anything on the current record as needed.
Script Include:
function dynamicViewRule(){
// Set return based on the condition field we're using
var trueCondition = current.number;
var falseCondition = "No View Rule";
var result;
// Condition to evaluate
if(current.short_description == "Test Major Incident"){
result = trueCondition;
}else{
result = falseCondition;
}
return result;
}
Basically if my conditions match I return the current number which matches the condition builder selection. If my condition doesn't match, I return a string that doesn't match anything so that the condtion builder "Number == 'No View Rule'" results in false and isn't applied.
Result: The view rule is applied where my short description matches the condition
If I add an "s" to the end of the short description and save it, the condition no longer matches. The view rule no longer applies and I can change the view:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2015 07:56 AM
I've implemented this configuration 1 for 1 and it does not appear to be doing anything. I noticed in your Script Include function above, the syntax for your form doesn't look like anything i've seen in a Script Include. Could that perhaps be for a Business Rule? or UI Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2015 08:10 AM
on a business rule (display BR) , you can add the condition to get the user details and based on that you can take the URL using and change the value of "sysparam_view"
Just thinking loudly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2015 08:15 AM
How would I obtain the url? This form is being viewed via the ESS and when I use something like window.location or location.url, i get a very long URL. How would I apply the view to the url? I know I would have to use &sysparm_view=my_view_name but i tried that before and it had no effect.