I might be asking trivial questions but I really couldn't figure them out
In a very simple pgsql form submit, some of foreign key need to be null instead of "" otherwise I get below error
My first thought is to use inline js to replace "" with null inside Changeset -> Object -> {{form.data}}, but immediately I get run into a error object.keys() is not a function shown in below screenshot.
I already changed all the field default value to null as a workaround
Then I want to inset modified_at, but then run into another problem where the value would replace the whole object rather than append
Am I doing something stupid?
Or there's some other limitation that retool does not run certain inline js?
Hello, you would need to iterate thru the form data and create a new object with the overwritten values, as following
let newObject = {}
Object.keys(form1.data).forEach((key) => { // iterate thru each key of form data
if (form1.data[key] === "") { // if form data [key] value is an empty string, replace it with null
newObject[key] = null
} else { // else, keep the current value
newObject[key] = form1.data[key]
}
})
return newObject
I thought about creating a JS query which would allow multi-line js code, which I'd assume would be the best practice here.
What's been bugging me is understanding limitation of {{js}} in Retool. after reading the documentation, I thought as long as its one line JS, retool can handle it . apparently there's deeper limitation that I do not yet understand