Call JS-Function from catalog item script in catalog variables "Default value"

Vespertinus
Tera Expert

Hello SNow community,

i have often used "javascript:gs.getUserDisplayName()" in catalog items variables "Default value" field to dynamically set logged in user.

I now also want to call a function stored in catalog item script (type onLoad) to dynamically load values.

Variable:

Eg "javascript:mycustomclientscriptfunction()" -> "Default value"

Catalog Item script (onLoad):

function mycustomclientscriptfunction(){

  return 'test';

}

Unfortunately this did not work. How to achieve this? Any hints ideas? Maybe there is a better way to go with "overall" ScriptIncludes? Do you have some samples for this?

Thx a lot and best regards

Vesp

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

You can't call a client script or any client side code from the default value. You should be able to call an OOB or your own script include from the default value field, though.



Specify a default field value


View solution in original post

7 REPLIES 7

SanjivMeher
Kilo Patron
Kilo Patron

You can write the whole script in the default value as well.



find_real_file.png



You should also be able to call a global script include. But I haven't tried it.



Please mark this response as correct or helpful if it assisted you with your question.

Sharique Azim
Mega Sage

Hi vespertinus,



Unfortunately, i dont think its possible, in the default value to call client script codes.



Why dont you extend the onLoad Client script to set the values based on conditions. Or you can use several Ui Policies to set the default values.



or dynamic reference qualifier   like user manager is(dynamic) me( if the field is reference type and the table is sys_user)



Regards,


Shariq


While, answering i would also request to clarify the need for the default value setting in the variable.



Regards,


Shariq


Brad Tilton
ServiceNow Employee
ServiceNow Employee

You can't call a client script or any client side code from the default value. You should be able to call an OOB or your own script include from the default value field, though.



Specify a default field value