Storing hashmap in memory in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 11:38 AM
So let's say I have the following function as an example which is a scheduled job that runs once a day:
function buildMap(){
var hashMap = [];
hashMap["basketball"] = "ball";
hashMap["hockey"] = "stick";
hashMap["tennis"] = "racket";
}
Is there a way to store this hashMap variable above so that it can be accessed whenever I want?
Let's say this scheduled job runs at midnight once a day, but I want to have a fix script for example which
I would like to run manually, to be able to check for a specific value which was built previously by this scheduled
job. Is this possible in ServiceNow without having to rerun the scheduled job again when I want to access the
value in a hash map?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 12:09 PM
HI,
I dont know if i understood you correctly. You want to have this function handy right, then you can directly store this in script include and call that from there or even in the same fix script you can store it if this is static.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 02:31 PM
The scheduled job will kick off this function. Then the fix script will utilize the hash map value. The idea is to not run this function on demand, but to only have it run once a day; however, accessing the hash map array should be on demand without running the function. Hopefully that makes sense.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 01:33 PM
Since you only want to run this once a day, your best bet would be to create a custom system property in the sys_properties table that you can set with the result of your scheduled job. Then, whenever you need the value, you just read the value from the system properties. Reading the value is fairly simple, you can just use something like this:
var myHashMap = gs.getProperty('your.custom.variable.hashmap');
If you also need to access it from the client side, you can use the g_scratchpad API to pass the value of the property to a form when it loads and then it is accessible on the client side as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2020 02:28 PM
When creating a custom system property, there's no option for array or hash map. The options in the list only contain things like "string", "integer", etc.