Pull data resource once, then reference everywhere

What’s the best way to pull a data resource once and then be able to reference it later, without having to make additional API calls?

I have lists that will not change at the data source, so I would like to pull them in as globals and then use various functions later to search through them and returns temporary subsets to the UI.

Thank you!

You can create and configure a client-side storage data resource with a schema matching that of the result given by the API call. Then write the result of the call to the storage resource. You’ll then be able to load up the resource anywhere in the app and use the data stored there. Basically, you’re caching the data. I haven’t got a clue about any storage limits, so do test it.

Thank you, Juan! I will give this a try.

Hi @David_Diamond, a data variable makes an API all every 5000ms by default, so I would suggest you remove the delay logic after successful “Get record collection” on the Logic canvas if you decide to use one:

Another way to do this is to create a “List of Objects” type app variable that matches the schema of the list coming in from your API. Then when the app launches, get the data with a Get record collection node on the Global canvas page, and set the app variable to its output value.

The benefit of this method over using a data variable is that while the data variable will only be accessible on one page of the app, you can access an app variable anywhere.

Thank you, Mari! I will give that a try, too.

I do disconnect that loop for the data variables where it’s not needed. I hadn’t tried the app variable idea, mainly because I was too lazy to recreate the entire schema manually, and I wasn’t sure that was a good solution. But I’ll give it a try now. :slight_smile:

1 Like

Is there something different about App variables that prevent them from working with various functions? I’ve created the app variable, and I’m able to reference the items from a list. But when I click into the list to open a details page, I can’t for the life of me figure out how to reference a given object within the App variable. I’ve tried FIND, LOOKUP, INDEX-OF, etc. They all complain about a type mismatch between objects and lists.

I want to be able to pull values from the clicked list item record on the previous page. I just can’t figure out why this isn’t working for me.

Do you need to call the API to retrieve the data every time your app launches? In that case, you should try Mari’s approach and use an app variable within your Global Canvas which you use to store the results from the API call. On the other hand, if your data doesn’t change and you only need to load it once, it’s best to save it into client-side storage. You can then retrieve anywhere in the app where you place your data variable. You’d still need to make sure both schema match though.

There are two ways to do this: either set parameters into your details page which you pass from the list item you’re clicking (I don’t like this because unfortunately parameters can only be text types, and thus they are quite annoying to work with if you have non-text data), or you pass an id parameter to your details page and then filter the element with that id within your list using something like FIND_BY_KEY.

Hi, what kind of mismatch do you mean? You can use FIND(appVars.items, item.id === params.id) to get the object that matches the id you pass as a page parameter. SELECT is useful for filtering.

What I’m trying to do is get a list of objects based on a field value of those objects.

In the attached image, if I do a FIND BY KEY on “id” it works. But I need to find all records whose Region field (for example) holds a given value. I’m trying to reference the field by its key, and also via “fields.Office”, but neither works. Appgyver shows me a complete path to the field, but it includes [0], which I’m guessing is restricting the search to that index item.

I’m sorry this is so confusing. Chances are, if I knew how to ask in a way that wasn’t confusing, I’d probably be able to figure out what’s wrong. :slight_smile:

Thank you for any help you can offer!

Hi, if you check out the docs you can see that the inputs of SELECT_BY_KEY are:

  1. Array you are searching in
  2. Name of field you’re filtering by
  3. Value you are searching for

SELECT_BY_KEY(array1, "a", 2)

In your case that would be:

SELECT_BY_KEY(appVars.gMeetings.fields, "Region", "The region you are looking for")

Thanks for the reply. But it’s still giving me the errors. I promise you that I’ve been reading the docs inside and out. :slight_smile: Any other ideas of what might be wrong?

Ah, I mistook fields for the list you’re filtering, sorry!

So if appVars.gMeetings is the list you are filtering in, and you want to search for items where fields.Region equals “Truckee”, you can use:

SELECT(appVars.gMeetings, item.fields.Region === "Truckee")

Thank you for your help, Mari. I really appreciate it.

1 Like

"Hi David_Diamond, a data variable makes an API all every 5000ms by default, so I would suggest you remove the delay logic after successful “Get record collection” on the Logic canvas if you decide to use one…"

Figured that one out the hard way when we blew through 10,000-15,000 API calls in one day just having a single user’s profile page open. So are you saying, if we remove the delay, then it’ll only make the call once when the page is loaded? That makes sense. I was just under the impression the delay component is slowing down the call rate – and that without it, it would call several times a second or so.

So we actually used a longer delay (say, two minutes) to save on calls. But if we can just remove it and have it fire once on page load, that would be even better. Thanks!

Hi, yes @Dominik_Greene – in the 2nd picture in my comment that you’re referencing, it works like this:

  1. Page mounted
  2. Get record collection
  3. 1st output triggered → data retrieved successfully → set data variable (data won’t be retrieved again unless you use Get collection again somewhere else in the app)
  4. 2nd output triggered → failed to retrieve data → 5000ms delay → will try to get record collection again.

So by removing the wire that goes by default from the 1st output of Get record collection to the Delay node, you can disable the automatic refreshing of data.

1 Like

Makes sense now. It’s just a loop. Great, this works for us! Much obliged. :slight_smile: