How to clear context?

Is there a way to clear entire context? I've found two ways to do that:

  1. Use Switch -> delete.flow but it needs to be specified unless there is some way to delete all?
  2. Use context.set() = undefined but it doesn't seem to work at all, I'm using it like this:

Not out of the box. You would need to get the keys and iterate them, setting each one to undefined

const keys = flow.keys()

for (let index = 0; index < keys.length; index++) {
    const key = keys[index];
    flow.set(key, undefined)



Store all your context variables in a single object, then you can just delete that 1 single object.


Thank you very much, this works perfectly

Could this also be used to reset all context context instead of flow context?

I tried

const flowkeys = flow.keys()
for (let index = 0; index < flowkeys.length; index++) {
    const flowkey = flowkeys[index];
    flow.set(flowkey, undefined)
const contextkeys = context.keys()
for (let index = 0; index < contextkeys.length; index++) {
    const contextkey = contextkeys[index];
    context.set(contextkey, undefined)
return msg

but the context context were not deleted. I would imagine maybe because they are not available outside of the respective nodes.

It would only work for the own nodes context. So for every function you have context, you would need to run that code.

You could setup a conditional section of code e.g.

if(msg.topic === 'clear') {
   // clear context code
// other code here

In each of the functions.

Or, better, set up a link call subroutine and send the context to clear to a common "clear context" subroutine. So you don't have code duplication.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.