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

Hi @Chaitanya ILCR

I tried with Try Catch but cannot see any error message. Also there is no issue in the  Script Include 

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