View rule

Danit Shabtay
Tera Contributor

Hi All šŸ˜Š

I need in the incident table:

1. Create a new view named: manager view

2. Create a new choice field called "selected view" (contains 2 options: default view, manager view)

3. When selected view = manager view --> The view of the incident will be manager view,
and when selected view = default view The view of the incident will be the default view

 

I did task 1 and 2
How can I do task 3 using view rule?

The view should change automatically (and not manually) according to the value of the field - "selected view".

 

 

3 REPLIES 3

Karan Chhabra6
Mega Sage
Mega Sage

Hi @Danit Shabtay ,

 

You need to create an onChange client script to change views dynamically based on the choice selected.

Client script : type - onChange, Field - selected view

Please check if the backend names of choice and view is same, if not - change it accordingly in the script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   if(newValue == 'manager_view'){
switchView('section','incident','manager_view');
}
else if(newValue == 'default_view'){
switchView('section','incident', 'default');
}
   
}

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

Amit Gujarathi
Giga Sage
Giga Sage

HI @Danit Shabtay ,
I trust you are doing great.

To achieve task 3 using view rules in ServiceNow for the incident table, you can follow these steps:

  1. Go to the ServiceNow platform and navigate to the "Incident" table.
  2. Open the "View Rules" module.
  3. Create a new view rule by clicking on the "New" button.
  4. Provide a name for the view rule, such as "Automatic View Change".
  5. In the "Table" field, select "Incident" to specify that the view rule is for the incident table.
  6. In the "When to run" section, choose the option "Before query is executed".
  7. In the "Advanced" section, specify the following condition:
    • Condition: selected_view
    • Operator: is
    • Value: manager view
  8. In the "Actions" section, select the option "Set the active view" and choose "Manager View" as the view to be activated.
  9. Click on the "Save" button to save the view rule.

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



6 - In the "When to run" section, choose the option "Before query is executed".

 

Where is this option? There is no "When to run" on view rules?