I have a form and user enters their code and I am trying to connect it to a Server action which runs a query based on the code they entered, if the query returns a result (I used ‘count’ here, there will always be 1 or nil counts), then they can be redirect to a specific page, otherwise an error message shoulder appear.
You cannot use serverside redirect for that. You need to use the browser component on the page and use it to redirect.
You can achieve this using a response step in the server action:
Condition - query count != 1
Then -> response 400 / invalid
Else -> empty
On the front end, on form dynamic events:
server action onsuccess -> browser goto … some page
serveraction oninvalid -> show some alert/notification/toast
@Teodor, half way there. alert comes up, but when correct the browser goto doesn’t work and still displays alerts.
Not sure what I am doing wrong.
Just confirming, the “then” “text” is “some string” - does it have to be anything specific.
I have checked the query to make sure it works and returns a value.
@Teodor, In the browser dev tool, it gives me a “400” response when the condition is false (query count ==1).
On checking the query again, it seems to be giving me "some string’ output regardless.
If you get a response of 400, then then the condition is met … i.e. count does not equal 1. Maybe check how do you filter the query and check if the record really exists …
It look like the ‘count’ in the query isn’t working, even though the query does return a record. I tried it without the count and just put a value that exists in the table and it worked. So not sure why count isn’t working?
I don’t know why is it not working in your case, i just tested this and it works fine.
What query are you using - single, paged, multiple?
What server model are you using?
Well ... single queries do not return array. You can't use the count formatter with it.
For single query just use {{!query}} as a condition where query is the name of your query of course.
@Teodor, just a quick one, I am trying to limit/stop the user from entering more than 4 digits in an input form field - lets the user enter more than four. anyway we can restrict so they.
Maxlength doesn’t seem to stop the user entering more than 4.
What am I doing wrong?
Look for warnings in the dev console. Perhaps the validation scripts are not added or you haven’t saved your layout, which is where the scripts would be.