opened
carlosfaria94
username_0
I need to pass context from a Operation Hook (persist) to another (after save), I know the [existence][1] of the `ctx.hookState` but its not working.

    ZZ.observe('persist', (ctx, next) => {
          ctx.hookState = "pass this";
          next();
        }).catch(err => next(err));
      });

    ZZ.observe('after save', (ctx, next) => {
      console.log(ctx.hookState);
      next()
    });
    

I don't get anything in `console.log(ctx.hookState)`. What I'm doing wrong?

Thanks.

  [1]: https://docs.strongloop.com/display/APIC/Operation+hooks#Operationhooks-SharedhookStateproperty
Pass context in 'persist' to 'after save'
issue
created
Amir-61
username_1
Which method are you calling? Please provide a sample repo reproducing the issue using our [loopbakc-sandbox](https://github.com/strongloop/loopback-sandbox).

Thanks!
comment
created
carlosfaria94
username_0
I'm calling a create method. It's here: https://github.com/username_0/loopback-sandbox

As you can see: https://github.com/username_0/loopback-sandbox/blob/master/common/models/foo.js I'm using `ctx.hookState` to pass a string between hooks, as described [here](https://docs.strongloop.com/display/APIC/Operation+hooks#Operationhooks-SharedhookStateproperty ).

Maybe I'm doing something wrong?

Thanks
comment
created
carlosfaria94
username_0
Anything? bug?
comment
created
Amir-61
username_1
Sorry I did not get time to verify it. @username_2 since you are on triage sprint, could you please verify this based on the sandbox provided? Thanks
comment
created
0candy
username_2
@username_0 You can do this:
```
    Foo.observe('persist', (ctx, next) => {
        if (ctx.currentInstance) {
            ctx.hookState.x = 'pass this';
            console.log('hookState in pesist: ');
            console.log(ctx.hookState);
            next();
        } else {
            next();
        }
    });

    Foo.observe('after save', (ctx, next) => {
        if (ctx.isNewInstance) {
            console.log('hookState in after save: ');
            console.log(ctx.hookState);
            next();
        } else { 
            next();
        }
    });
```
comment
closed
carlosfaria94
username_0
issue