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

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Antonio,

 

Could you please share the script?

 

Thanks,

Pradeep Sharma

Pradeep, thank you for your quick reply!

function onLoad() {
    var viewName = getView();
    var grView = new GlideRecord('sys_ui_view');
    grView.addQuery('name','Default');
    grView.query();
    while(grView.next()){
        if(grView.name == viewName){            
            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');}
        }
    }
}

also i ma wondering what is the use case to include view name in the script here.

basically here in script you are checking for all views with name "Default" and again comparing same with form view. 

if you want the change for only particular view then you can directly compare the view name with viewName variable in your code.

why extra GlideRecord?

 

Please let me know if i am missing something.

 

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, I have several views, in this case the script must run only to this view that's why condition was applied.