Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Make Mandatory for multiple views using UI Policy

Deborah Brown L
Kilo Sage

I need to make many fields mandatory but only for 2 views.

I can see there is a field in the UI Policy for view. but I can add only 1 view in the field.

I need to add 2 views in it.

Can we achieve it only if we create 2 individual UI policy.

 

DeborahBrownL_0-1720502145075.png

 

1 ACCEPTED SOLUTION

Vrushali  Kolte
Mega Sage

Hello @Deborah Brown L ,

 

One way to achieve it by creating on load client script and using g_form.getViewName() method to get the current view as follows-

Further you can build if condition to make fields mandatory for those particular views.

 var view = g_form.getViewName();
if(view == 'default' || view == 'abc'){ //Replace the view name
   g_form.setMandatory('field_name', 'value');
}

 

If my answer solves your issue, please mark it as Accepted✔️ and Helpful👍 based on the impact.

View solution in original post

2 REPLIES 2

Rupanjani
Giga Guru

 

Hi @Deborah Brown L,

 

In scripts, you can use g_form.getViewName(). 

 

if (g_form.getViewName() == '<view_name_1>') { //different set of fields use this, else you can add the other view condition with ||
g_form.setMandatory('<field_name>', true);
//any other
} else if (g_form.getViewName() == '<view_name_2>'){ 
g_form.setMandatory('<field_name>', true);
//any other
}

 

 

 


Mark the response correct and helpful if the answer assisted your question.

Vrushali  Kolte
Mega Sage

Hello @Deborah Brown L ,

 

One way to achieve it by creating on load client script and using g_form.getViewName() method to get the current view as follows-

Further you can build if condition to make fields mandatory for those particular views.

 var view = g_form.getViewName();
if(view == 'default' || view == 'abc'){ //Replace the view name
   g_form.setMandatory('field_name', 'value');
}

 

If my answer solves your issue, please mark it as Accepted✔️ and Helpful👍 based on the impact.