Share a javascript variable between client scripts on the same form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-04-2018 08:02 PM
I have a two client onchange scripts that both need to adjust a javascript variable. Both scripts are started by a change in different fields on the form. one script adds 1 to the variable, the other subtracts one from the variable. Is there anyway for these two scripts to share access to the same javascript variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-04-2018 08:20 PM
Did you try with g_scratchpad
https://servicenowgems.com/2016/10/10/understanding-scratchpad-g_scratchpad/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-04-2018 08:27 PM
This will use a call to the server correct? In the native UI I can declare:
var count = 27;
and in two different onchange client scripts i can use or change the variable count and i do not need to contact the server.
However in the serviceportal I can not declare a variable and then access it in a different client script of the same form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2018 01:18 PM
I'm curious if "g_scratchpad" Object is the proper way to share data across client scripts.
The post you have mentioned describes the way to pass data from a Business Rule to Client Script. The same use case we can find in official docs.
The "g_scratchpad" look really like it would be a good and safe place for sharing and persisting data. I would really like to hear something from any ServiceNow Platform Developer about this topic.