Cannot set a date field

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [ ] Performance issue
  • [x] Documentation issue or request

Current behavior

Trying to set a ‘Change’ script to fill in a ‘publishedDate’ and ‘archivedDate’. I’ve tried multiple versions of adding the date value to my Date Time field like (Tried separately of course)

data.publishedDate.iv = ctx.lastModified;
data.publishedDate.iv = new Date();
data.publishedDate.iv = new Date().toISOString();

Expected behavior

I would like to fill the field with the current date using the scripting utilities.

Minimal reproduction of the problem

Schema field

{
	"name": "publishedDate",
	"properties": {
		"fieldType": "DateTime",
		"editor": "DateTime",
		"label": "Published Date",
		"hints": "Date of first publishment"
	},
	"isDisabled": true,
	"partitioning": "invariant"
},

Script:

if (ctx.status === "Published"){
        var data = ctx.data;
        data.publishedDate.iv = new Date().toISOString();
        replace(data);
} 

Environment

  • [ ] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [x] Cloud version

Browser:

  • [ ] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge
  • [x] Brave

Others:

I was able to set the property to null, as I received that value through my API call. So the script gets called, My guess is that my value is denied for a date time somehow.

It’s very difficult to debug this, and I find the documentation a bit lacking of the scripting.
I’m super thrilled to use Squidex and I love the platform!

:tada: Happy new year, as well! :slight_smile:

Hi, happy new year as well.

I think the problem is that currently the dates doe not accept milliseconds. You can use this approach: Schema script help

Thanks

This solved it!
First bug of the new year solved! :ballot_box_with_check:

1 Like