How to change the Form - view based on field value

KeerthiPraV
Tera Contributor

I have a Custom table, In that table ticket type(Choice field) have 2 values.
If i select one value it should change the view to another view, if i select 2 value it should change the view accordingly.

Can you please help me to configure it.

2 ACCEPTED SOLUTIONS

Dr Atul G- LNG
Tera Patron

Hi @KeerthiPraV 

As per best practices, this is not a recommended approach. Changing the view based on a field is not a good solution and does not align with the process. Either show the correct view at the beginning or use a client script to hide or show the field.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

@KeerthiPraV 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

MohamedZ
Tera Sage

Hi @KeerthiPraV 

What's the use-case here?

 

I tried on the Incident form using an onChange Client Script on the Category field to switch views for hardware and software:

 

function onChange(control, oldValue, newValue, isLoading) {  
if (isLoading || !newValue) {

        return;

    }

    var view = {

        "hardware": "ess",

        "software": "major_incidents",

    };

    var targetView = view[newValue.toLowerCase()];

    if (targetView) {

        switchView("section", "incident", targetView);

    }

}
 
Drawbacks:
1) Does not work when record is new
2) if record exist, need to save the record first and then proceed with change in field which pops up dialog box as shown below, after clicking leave reloads form with changed view.
 
Mohammed8_0-1768862760478.png

 

Mohammed8_1-1768863134618.png

 

I searched but could not find workaround for above mentioned draw backs 
 
Instead of switching views, you can use UI Policies to show/hide sections or fields based on values
 
If this was helpful, please mark it as helpful.
 
Regards,
Mohammed Zakir

Hi @KeerthiPraV 

just following up to see if you had time to review this?

 

Regards,

Mohammed Zakir

Ankur Bawiskar
Tera Patron

@KeerthiPraV 

you should not switch view in between when form is already loaded as it might cause loss of data

Instead you should use View Rules

Create a view rule 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@KeerthiPraV 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader