OnLoad client script does not run to non-admin role (non-admin role/user has ITIL)

Antonio42
Kilo Guru

Team,

I created an onload client script to set category, assignment group and other fields to speed up the fill out of form, you guys know time is money 🙂

Everything works nice when I create a new incident since my userID is associated with admin role, but when any user out of admin role goes to new incident, the onload client script does not work, that user has ITIL role, ok? Have you already seem this before? Appreciate any help!

 

1 ACCEPTED SOLUTION

Then in that case you can directly have view name to compare in the script. try below script

 

function onLoad() {
    var viewName = getView();
  
        if(grView.name == "default"){ //here you know for which view the script should work. so you can directly compare view name. if it should apply for multiple views, you can have or (||) condition in if().
            g_form.removeOption('u_qs_type','Alert');
            g_form.removeOption('u_qs_type','Incident');
              if (g_form.getValue('category')=='' || g_form.isNewRecord() == 'false'){
                g_form.setValue('category', '1');}
            if (g_form.getValue('assignment_group')=='' || g_form.isNewRecord() == 'false'){
                g_form.setValue('assignment_group', 'ab08f792db946b006769980c8a961455');}
        }
    }
}

 

let me now for any query.

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

10 REPLIES 10

Then in that case you can directly have view name to compare in the script. try below script

 

function onLoad() {
    var viewName = getView();
  
        if(grView.name == "default"){ //here you know for which view the script should work. so you can directly compare view name. if it should apply for multiple views, you can have or (||) condition in if().
            g_form.removeOption('u_qs_type','Alert');
            g_form.removeOption('u_qs_type','Incident');
              if (g_form.getValue('category')=='' || g_form.isNewRecord() == 'false'){
                g_form.setValue('category', '1');}
            if (g_form.getValue('assignment_group')=='' || g_form.isNewRecord() == 'false'){
                g_form.setValue('assignment_group', 'ab08f792db946b006769980c8a961455');}
        }
    }
}

 

let me now for any query.

 

Thanks,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Ali, you are right! I just removed the GlideRecord and compared the view directly, it worked to admin and non-admin role! thank you so much

Antonio42
Kilo Guru

Any idea what's happening?

Hello,

 

GlideRecord should not be used in client scripts.

Use GlideAjax instead.

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference/r_ExamplesOfAsynchronousGlideAjax.html

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

It works to my admin user. According to your statement it wont work using gliderecord right?