How to set one view on a list and another view on the form?

PerV
Kilo Sage

Hi all!

I need to find a way to set a specific view when viewing a list, but when I view the form for the record I need to redirect to another view. How do I accomplish this?

The situation is:

Two different areas within the organization need different list views (different columns). However, when they open a record in that table we only have one view which both of them should get.

I have a view rule for the two different organization areas, and the view rule work, but of course the view is inherited to the form, which forces the Default view on the form. I do not want to maintain two different form views too.

Any ideas? I have found a couple of articles here in the Community (https://servicenowgems.com/2013/12/06/force-a-view-from-a-module/ for example, but I don't understand how the sysparm_view could be adapted to my needs), but nothing exactly like my situation.

Best regards

Per

2 REPLIES 2

ohhgr
Kilo Sage
Kilo Sage

Hi Per,



One way would be to write a script that forces the view to be changed as per this article https://www.servicenowguru.com/scripting/client-scripts-scripting/change-form-view-client-script/ .



Please note that the view would be switched after the form loads, so it would result in the form loading two times, in case the view is different.



Hope that helps.


-Mandar


Thanks Mandar, I tried but did not have any luck with that. I want to avoid reloading the form if possible.



One thing in that article led me to another view rule that suggests it is possible to determine if it is a form or a list though, I am testing that now. See example below:



(function overrideView(view, is_list) {


var isSysAdmin = gs.hasRole("admin");


var isCustomer = gs.hasRole("sn_customerservice.customer");


var isCustomerAdmin = gs.hasRole("sn_customerservice.customer_admin");


var isPartner = gs.hasRole("sn_customerservice.partner");


var isPartnerAdmin = gs.hasRole("sn_customerservice.partner_admin");



if((isCustomer || isCustomerAdmin || isPartner || isPartnerAdmin) && !isSysAdmin){


answer = "csp";


if (is_list && (isPartner || isPartnerAdmin))


answer = "csp_partner";


} else if (gs.nil(view))


answer = "case";


else


answer = view;




})(view, is_list);



Line 10: if (is_list...) gives me some hope that it is possible to affect the list view only. So far I have had no luck, unfortunately...



/Per