The CreatorCon Call for Content is officially open! Get started here.

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

Hallo Brad, thanks for clarification. Do you have a sample for calling a script include from default value? I have not seen this so far. As i "simply" want to preload some data, i want to avoid bigger catalog item script (client side).



Thx & br,


Vesp


Hey,



"javascript: new ScriptIncludeName().FunctionName()"


Vespertinus
Tera Expert

Thanks for all the fast replies. With samples from Brads link i could manage to directly use needed Javascript in Default Value field (without calling catalog item script or script include).