I have a table inside a retool database and have a query to update that table.
I want to run that query from javascript, but always get a 422 error ('A changeset must be specified'). I have this code now and have tried all kinds of formatting for the changeset object inside the additionalScope object.
If not how else can i pass a key/value pair as changeset when triggering a query. I don't want to have to make umpteen queries with predefined changesets for all possible table updates.
Instead of trying to set that value directly, can you pass it through additional scope and then reference it in the query using the 'Object' tab instead of 'Key value pairs'?
I think you've got a couple things going on here, so let me know if this is what you're trying to do.
From your JS script, you want to trigger that query. The query matches the row to update based on some input fields elsewhere in your app that map to the columns Titel and Text.
For that matching row, you want to update the column Annif_KL_OmiPar to the value Bad?
If that's what you're trying to do, I would suggest changing the value of eval to:
if (pickModel.value == 'KLZIZO_selected') {
// Notice the change here, both the object and the name - avoid "eval" in JS
let evalData = { "Annif_KL_OmiPar": "Bad" };
await model1.trigger({
//Changed this as well, so we pass the evalData object as additionalScope
additionalScope: { evalData },
onSuccess: function (data) {
console.log(data);
},
onFailure: function (error) {
console.log(error);
},
});
}
Then in your query, change the Changeset section to Object instead of Key value pairs,
The object-method resulted in a statusCode:422 error:"Unprocessable Entity" at first, so different error. Which led me to adapt the filter and use a filter on id (primary key) instead. When configured like that the update method/query works.
But that means I need to know the id already which I don't when running the query.
I could write another query that looks up the title/text combination and returns the id, then use the value that query returns in the update-query. Would prefer a more elegant solution with just 1 query though, is that possible?
@Kris - What do your other inputs look like? The ones used in the filter. If they are on the page, it should work using the 2 filters for Title and Text. Maybe try console.log'ing them from your function to confirm they are accurate. I can't tell what they are in the original screenshot, but "Title" is spelled differently in the column name vs the variable name "Titel" vs "Title", and the Text value looks like it might be a couple different value?
The spelling difference is because my data is in Dutch but I'm writing my code in English
But I figured out what whas happening, feel so stupid, there was an unwanted empty space inside the 'Titel' string in the database which made it differ from the input value
Haha I knew Titel could have been right, so I didn't want to call it a "Typo", just funny to see it used both ways at the same time! Glad you figured it out!
I'm also getting this error. Have you resolved yours? I'm trying to update a firebase realtime database entry through a component script. I've been on this for some days now. Someone should please help me out. @Kris@kschirrmacher@MikeCB@OOSC3