May I have one more question regarding passing the context from beforeSave
to afterSave
? I have two simplified triggers:
Parse.Cloud.beforeSave("Group", async ({object, context, log}) => {
if (object.existed()) {
if (object.dirty('lks')) {
//passing in context that lks was dirty as in afterSave, no key is dirty anymore
context = { newLostKey: true };
log.info(`beforeSave triggered for group: ${object.id}, lks dirty, context.newLostKey: ${context.newLostKey}`);
}
}
return;
});
I see in the dashboard log:
2021-09-24T07:16:24.143Z - beforeSave triggered for group: OsUpGGvgKG, lks dirty, context.newLostKey: true
When I try to check against this bool in afterSave
it seems to be undefined:
Parse.Cloud.afterSave("Group", async ({object, original, context, log}) => {
log.info(`afterSave triggered for group: ${object.id}, context.newLostKey: ${context.newLostKey}`);
return;
});
as it logs in the dashboard:
2021-09-24T07:16:24.152Z - afterSave triggered for group: OsUpGGvgKG, context.newLostKey: undefined
How should I pass it? I noticed that in the documentation is the context not in the trigger parameter Parse.Cloud.beforeSave("Group", async ({object, context, log})
but I don’t see it undefined in the first log entry
Many thanks!
EDIT
It seems that it indeed makes a difference. Adjusting it according to the example it pass the key:
Parse.Cloud.beforeSave("Group", async (request) => {
const { object: object, log } = request;
if (object.existed()) {
if (object.dirty('lks')) {
//passing in context that lks was dirty as in afterSave, no key is dirty anymore
request.context = { newLK: true };
log.info(`beforeSave triggered for group: ${object.id}, lks dirty, context.newLK: ${request.context.newLK}`);
}
}
return;
});
I believe the old way it assigned the context as a new object and not part of request
.
Parse.Cloud.afterSave("Group", async (request) => {
const { object: object, original, user, context, log } = request;
log.info(`afterSave triggered for group: ${object.id}, context.newLK: ${context.newLK}`);
return;
});
Returns correct true flag from context
2021-09-24T08:15:23.934Z - afterSave triggered for group: OsUpGGvgKG, context.newLK: true