Why View rule script is not working ?

Virendra K
Kilo Sage

Hi All,

 

I have created below View rule and put the logs but its not getting trigger. Is my script is correct  ?

Please suggest,

 

Script:

(function overrideView(view, is_list) {

    gs.log("VK passed");
    var url = gs.action.getGlideURI().getMap();        // I tried with this line
     //var url = gs.action.getGlideURI().toString();  // as well as I with this 
    var sysId = url.get('sys_id');
    var catType;
    var grChg = new GlideRecord('change_request');
    if (grChg.get(sysId)) {
        catType = grChg.u_cat_type;
        gs.log("VK  IF "+ sysId + "  "+ catType);
        if (catType == 'XECHG') {
            gs.log("VK  IF Passed");
            var GroupMember = new changeMemUtils().checkNotGrMembership('change_XE_groups');
            if (GroupMember ) {
                gs.log("VK GrMem "+ GroupMember );
                answer = 'XEChg_View';
                return;
            }
        }

    }
  
 
VirendraK_0-1749743481609.png
 
Regards,
Virendra
1 ACCEPTED SOLUTION

HI @Virendra K 

check if there is any unnecessary field populated on the view rule

ChaitanyaILCR_0-1749811779404.png

couple things you can check

 

  1. override user preferences should be = true
  2. check if any condition is added and remove it 
  3. check if any other view rule is overriding your view rule
  4. if you instance is domain separated check if the change record domain that you are opening and view rule are same domain
  5. check if your view rule is overriding other view rule
  6. check any other view rule is acting on and change the order and see

change the gs.log to gs.addErrorMessage or addInfoMessage so that if the view rule runs you'll immediately see the message on the form and you don't have to open the logs to check

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Virendra K 

no log is coming? not even one?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar,
Yeah, not a single log is coming. Seems its not getting even getting enter in the scripting part ?
 

@Virendra K 

please try to use gs.info() and see

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

Chaitanya ILCR
Kilo Patron

Hi @Virendra K ,

 

you script looks good 

just put try catch and see if you see any error

(function overrideView(view, is_list) {
    try {
        gs.log("VK passed");
        var url = gs.action.getGlideURI().getMap(); // I tried with this line
        //var url = gs.action.getGlideURI().toString();  // as well as I with this 
        var sysId = url.get('sys_id');
        var catType;
        var grChg = new GlideRecord('change_request');
        if (grChg.get(sysId)) {
            catType = grChg.u_cat_type;
            gs.log("VK  IF " + sysId + "  " + catType);
            if (catType == 'XECHG') {
                gs.log("VK  IF Passed");
                var GroupMember = new changeMemUtils().checkNotGrMembership('change_XE_groups');
                if (GroupMember) {
                    gs.log("VK GrMem " + GroupMember);
                    answer = 'XEChg_View';
                    return;
                }
            }

        }
    } catch (err) {
        gs.addErrorMessage(err);
		gs.error('VK '+err);
    }

})(view, is_list);

 is this script include throwing any error?

 new changeMemUtils().checkNotGrMembership('change_XE_groups');

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya