Can i change request form view based on field value?

Rakhi1
Kilo Contributor

Hi,

I need to change my req form view based on one field value. If the field value is true, need to change the form view. Based on that, created view rule. But it is not working.

Tried with client script...

function onLoad() {

      var catlogitem = g_form.getValue('u_catalog_item_request');

      if(catlogitem=='true')

              {

              var sys_id = g_form.getUniqueValue();

              var url = 'sc_request.do?sys_id=';

              url += sys_id;

              url += '&sysparm_view=service_catalog&sysparm_view=service_catalog&sysparm_domain=null&sysparm_domain_scope=null&sysparm_record_row=4&sysparm_record_rows=2515546&sysparm_record_list=ORDERBYDESCnumber&sysparm_nostack=yes';

              top.window.location = url;

      }

}

Some how it is working but it opens a new page...because of that, nav menu, banner will not appear. I want to be on same page...and need to change form view.

I am using fuji.

Can anyone help me on this...Thanks in advance.

10 REPLIES 10

Chuck Tomasi
Tera Patron

Hi Rakesh,



Views were not meant to be changed dynamically (onLoad counts). The view rule contains the conditions of what view is used and when.



BTW, you have sysparm_view in your URL twice.



PS: If a view rule is in place and conditions match, then the sysparm_view doesn't count.



Reference:


View Management - ServiceNow Wiki


Capture.PNG



This is the view rule...


Based on condition, view should change to defined view. But not happening...


Thank you Rakesh!



Can you show me the form layout for the view called 'service_catalog' please?


Capture.PNG