Storing hashmap in memory in ServiceNow

Mike278
Kilo Explorer

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?

5 REPLIES 5

Ashutosh Munot1
Kilo Patron
Kilo Patron

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

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.

nancystodd1
Giga Contributor

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.

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.