Hi All,
it’s me again, this time i’m facing some issue managing a DateTime record field in the Corredor script, let me explain.
Some external Webhook trigger my workflow that parse the request body and pass it to a script, now inside my js code i’ve an object that has a Date in a string format (aaaa-mm-dd) and i want to store it inside my record, so i’m using a record field of type DateTime.
this is the snippet i’m using to “convert” the string into a DateTime object
customer.values.dob = new Date(args.dob)
the script does not block during execution so i’m assuming that the record creation is succeded but in my record page i can’t see the value in the field and if try to print using another workflow that search a record and print the value of Date i’ve got an error stating that there’s an interface error
format(“DoB → %v”, user.values.dob)" failed: expected type interface {} for parameter 1 but got <nil>
Does new Date(args.dob)
return a valid Date? Try console.log
over the value to see what it prints out.
If I recall correctly, passing a Date
object into a date time field should work. If not, try to convert it into the ISO 8601
string format (I forgot what the function is called but I know the Date
object has one)
this is the console.log of the record value just after the assignment
code
customer.values.dob = new Date(args.dob)
console.log('dob -> ',customer.values.dob)
Log in the terminal
dob -> 1976-10-02T00:00:00.000Z
everything look like it worked but in the page the field is empty
Does it go through if you convert the date object into the iso string?
Can you show how the module field is configured?
What version are you on?
i’m on the 2022.3.2
here’s a snapshot of the module field, i haven’t done other configuration
regarding the isoString conversion idk how to do it and test it
This is a console.log of what i get in the req Body
args -> 1976-10-02
Type : string
EDIT:
i’ve done some test using this reference
link
and the type of the value is a Date object, so i think there’s something like a validation on corteza server that erase the record or so
This are all of the supported formats – corteza-server/sanitizer.go at 2022.9.x · cortezaproject/corteza-server · GitHub
I can’t remember what happens to the Date object when it gets sent over the network; it’s probably getting converted to some strange string which we can’t parse. You can change it to an ISO like so: Date.prototype.toISOString() - JavaScript | MDN
Thanks, i’ll try asap
do i need to change the record field type to String ? or under the hood the server do something like a Date.parse ? EDIT → NO
EDIT. It Works !
1 Like