View Rules are not applied after clicking the Save button in the portal.

Karthik152
Tera Expert

I created a View Rule to display the view based on the customer type—ITSM Customer View for ITSM customers and Ozean Customer View for Ozean customers.

It works when opening the record in the portal, but after clicking any UI action, it switches to the CSP view. I want to restrict this behavior. I’m attaching the View Rule code below, screenshot for initial load, and after clicking the  UI action behavior

 

View Rule:

 

 

 


(function overrideView(view, is_list) {

    //gs.addInfoMessage('test');
    //gs.addInfoMessage(gs.action.getGlideURI().toString());
    var isPortal = gs.action.getGlideURI().toString().indexOf('portal_id');
    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");
    var isExternal = gs.hasRole("snc_external");
    //Customer roles for ITSM and Ozean views
    var isItsmcustomer = gs.hasRole("sn_customerservice.zf_itsm_customer");
    var isOzeancustomer = gs.hasRole("sn_customerservice.zf_ozean_customer");
    var isItsmAnalyst = gs.hasRole("sn_customerservice.zf_itsm_agent");
    var isOzeanAnalyst = gs.hasRole("sn_customerservice.zf_ozean_agent");
    if (isPortal > 0) {
        if (isItsmcustomer && !isSysAdmin) {
            answer = "ITSM_Customer";
        } else if (isOzeancustomer && !isSysAdmin) {
            answer = "Ozean_Customer";
        } else {
            answer = view;
        }
    } else if ((isCustomer || isCustomerAdmin || isPartner || isPartnerAdmin) && !isSysAdmin) {
        answer = "csp";
        if (is_list && (isPartner || isPartnerAdmin))
            answer = "csp_partner";
    } else if (gs.hasRole("sn_csm_ocs.ext_agent") && !isSysAdmin) {
        answer = "outsourced_customer_service";
    } else if (isExternal && gs.hasRole("sn_esm_location_agent") && !isSysAdmin) {
        answer = "external_location_agent";
        //Added ITSM and Ozean Customer role
    } else if (isItsmcustomer && !isSysAdmin) {
        answer = "ITSM_Customer";
    } else if (isOzeancustomer && !isSysAdmin) {
        answer = "Ozean_Customer";
        //End of the line
        //Added ITSM and Ozean Customer role
    } else if (isItsmAnalyst && !isSysAdmin) {
        answer = "ITSM_Analyst";
    } else if (isOzeanAnalyst && !isSysAdmin) {
        answer = "Ozean_Analyst";
        //End of the line
    } else if (gs.nil(view))
        answer = "case";
    else
        answer = view;

})(view, is_list);
 
 
1 REPLY 1

TamoghnaB
Tera Expert

Hi @Karthik152 ,

 

There must not be anything wrong with View Rule logic and that is why it is working correctly on load.

The issue is it is redirecting to another view whne you click on UI actions. 

In UI Action - you need to create the redirection logic to redirect back to same view.

Please apply the logic in your ui action. Please follow the syntax as belo:

 

// Redirect to the 'MyCustomView' of the current incident record
action.setRedirectURL("incident.do?sys_id=" + current.sys_id + "&sysparm_view=MyCustomView&sysparm_view_forced=true");

 

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

 

Thank you!