Schema script help

Hello, I am trying to write a schema script to write to a custom publish date field during the publish operation. I checked the docs site and couldn’t figure out how to do this.

What is the difference between the Change and Update events?
Do I need to call replace() or replace(data) at the end?
Do I need to all update() at the end?

Are there more examples somewhere for each of the events?

Update is called when the data is changed.
Change is called when the status is changed.

But at the moment you can only change data on either Create or Update.

You just need to call replace() when you want to replace the data with the updated version.

What exactly do you want to do?

Hi Sebastian, I would like to write down a date when content is published.

Perhaps I should make this the default anyway.

That would be fantastic.

1 Like

I will deploy a new version tomorrow.

What you can do then is the following:

if (ctx.status === 'Published') {
    // Get rid of the milliseconds.
    ctx.data.published.iv = new Date().toISOString().split('.')[0]+"Z";
    replace();
}

Btw: Do you use the cloud or self hosted?

Thank you! I use the cloud.