I am having difficulty polling an API for new IDs based on this workflow that I had found:
My understanding is that I need to get the global static data for a given workflow, and if a set which holds the IDs which have already been posted to Discord or Rocket.chat in the above example doesn’t exist, then I have to update the set for static data so it persists in the next run.
This is something like:
const staticData = getWorkflowStaticData("global");
if(!staticData.postedIds) {
staticData.postedIds = new Set();
...
// Add found Twitter IDs from the previous node to staticData.postedIds
...
// Return empty array so the next node where I post to discord doesn't post a bunch of IDs since postedIds was undefined so there were no previous executions
return [];
}
// Code here runs on next execution now that staticData.postedIds is a Set
const toPost = [];
// Check if new IDs have been posted
for(const tweet of items) {
if(!staticData.postedIds.has(tweet.json.id)) {
// Make sure the new ID is saved to postedIds so it doesn't get posted in the future
staticData.postedIds.add(tweet.json.id);
// Add to toPost array so that the next node will post the ID to Discord or Rocket.chat or whatever
toPost.push({json: {id: tweet.json.id}});
}
}
return toPost;
With this code, what happens is the line with if(!staticData.postedIds.has(tweet.json.id)) {
fails for me because staticData.postedIds.has
is not a function even though I had previously made the check and created a set in a previous execution. To be clear I am not manually executing the polling workflow I’ve made. I’m not exactly sure what is going on to get this error. It seems that if I use sets that it doesn’t seem to work with getWorkflowStaticData. This seems to apply to maps as well as I have tried those before in a different scenario too. However, when I use arrays it works just fine.
Unfortunately I cannot post the exact work I have done but hopefully this is a good enough explanation of my issue.