Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

how to switch view from ui action

jobin1
Tera Expert

Hi All,

How we can directly switch to a particular view from a ui action? Tried few scripts but not working as expected.

// Redirect to newly created record with view
        var url = '/u_email_client.do?sys_id=' + response + '&sysparm_view=genai_standardquery&sysparm_clear_stack=true';
        // window.top.location = url;
        g_navigation.open(url);
        //action.setRedirectURL(response);
        //g_navigation.openRecord('u_email_client', response, 'genai_standardquery');
        //g_navigation.openRecord('u_email_client', response, 'GenAI_StandardQuery');
        //g_navigation.openRecord('u_email_client', response, 'BPO_HRquery');
        //top.window.location = '/u_email_client.do?sys_id=' + response + '&sysparm_view=GenAI_StandardQuery';
    //  var url = new GlideURL(g_form.getTableName() + '.do');
    //     url.addParam('sys_id', g_form.getUniqueValue());
    //     url.addParam('sysparm_view', 'GenAI_StandardQuery');
    //     window.location.href = url.getURL();
        //action.setRedirectURL(current.getTableName() + '.do?sys_id=' + current.sys_id + '&sysparm_view=' + viewName + '&sysparm_view_forced=true');
        //var link ="u_email_client.do?sys_id="+response+"&sysparm_view=genai_standardquery";


Regards,
Jobin

5 REPLIES 5

Ankur Bawiskar
Tera Patron

@jobin1 

but why?

where you require this? native or workspace?

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

Dr Atul G- LNG
Tera Patron

UI action for view change, not a good way mate. Use OOTB way only and avoid technical debt.

*************************************************************************************************************
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]

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

Tanushree Maiti
Giga Sage

Hi @jobin1 

 

Check these posts.

 

https://www.servicenow.com/community/developer-forum/switch-the-view-using-ui-action/m-p/1986285

 

https://www.servicenow.com/community/developer-forum/redirect-from-one-view-to-another-view-using-a-...

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

RakeshM49470519
Tera Contributor

Hello @jobin1 ,
Try this script and it only works for form button

var view_name = "default";
var tableName=current.getTableName();
var url = tableName + ".do?sys_id=" + current.sys_id + "&sysparm_userpref."+tableName+".view=" + view_name;

action.setRedirectURL(url);