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

How to store rest API JSON response in cache in ServiceNow

dgarad
Giga Sage

 

We have a requirement to update the cards on portal, for that we are using count. We get the daily visited count for the cards from external source. Our requirement is to update the cards based on the count that we received.

 

We have one approach - creating custom table, for storing this count. We created cards records in that table and daily we are just updating the count in that table.

 

But our seniors are not agreed for custom table.

 

Instead of custom table. They suggested us to use utility to store the data in cache. And use the data in widget.

 

How to to build the utility for cache?

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad
6 REPLIES 6

Prince Arora
Tera Sage

@dgarad 

 

you can store data into window's session:

 

sessionStorage.setItem("Data", response_from_API_call); // storing data into the session
var data = sessionStorage.getItem("Data"); //getting data from the session

 

Can you take a look below thread, I have answered same type question earlier!

Link1  //please check first this

Link2 

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

@dgarad 

 

Have you looked at the solution?

Please mark it as accepted if it has answered your query!!

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

@Prince Arora 

 can we use  sessionStorage serverside script.

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

@dgarad 

 

for server side script please use:

 

for storing:

 

var session = gs.getSession();
session.putClientData('data', "your data"); //!!!! IMPORTANT need to pass string

for getting:

var session = gs.getSession();
session.getClientData('data');

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.