How to Create and Run a view rule on a Custom View Name (List)

robbcmd1234
Tera Expert

I want to run my view rule script on my custom list view named: Row 21 Affected User. But the view rule script only runs on the list default view.

 

image.png

 

What I'm trying to do is when there is at least one affected user field (custom field) that is not empty then the user can view the custom list view, otherwise it will redirect them back to the default list view.

 

I set the view variable in the script to "row_21_affected_user" and "row21AffectedUser". The script still runs on "Default view" and not on "Row 21 Affected User".

 

 

8 REPLIES 8

Astik Thombare
Tera Sage

Hi @robbcmd1234 ,

 

Checkout the Global Business Rule named incident functions

In the script you will find a function incidentGetViewName()

Make your coding changes in the function

 

 

// populate the default value for the caller
function incidentGetViewName() {
  if (gs.hasRole("your role name")) {
     answer = "YOUR_VIEW_NAME_HERE";
     return answer;
  }
  if (gs.hasRole("itil"))
     return; 
  if (view.startsWith("ess"))
     return;
  if (view == "sys_ref_list")
     return;

  answer = "ess";
}

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact

 

Thanks,

Astik Thombare

James Chun
Kilo Patron

Hi @robbcmd1234,

 

I tested the following script in my PDI which is very similar to yours and it's working fine.

(function overrideView(view, is_list) {
    answer = null; 
    if (is_list) {
        var myInc = new GlideQuery('incident')
            .whereNotNull('assigned_to')
            .count();
        if (myInc >= 52) {
            answer = 'Outlook';
        }
    }
})(view, is_list);

 

If you are intending the rule to be applied only to the list view, make sure you use the 'is_list' variable.

Is it possible that you have another View rule or something else that is overwriting the view?

 

Cheers

 

Hi @James Chun 

 

No, its the only view rule I created. Is it possible to make my view rule script to apply to Row 21 Affected User (custom) only and not the default view?
image 1.png

 

I tried these 2 and the script still only runs on the default view.

image 2.png

image 3.png

Just to make it clear, you are trying to change the 'default' view to 'row_21_affected_user' if an 'affected user' field is populated in any of the records (i.e. count is greater than 1).

 

Additionally, have you verified the name of the view is correct? i.e. go to [sys_ui_view] table and verify the 'Name' of the view.