Please help me with my Conditional Server Action

I have setup a conditional server action and I’m having problems with it. I haven’t done very many of these, so I’m probably missing something.

I have two server actions where I am inserting and updating, then I set up a condition where if my post variable is false, run an update query and if it’s not, run a different update query. Only the “else” statement runs no matter what the post value is.

Here is my condition:

Here is the value from my server action. You can see the “workstarted” value is false, but only the “else” query runs.

image

If you are sending false value as a string then it must be wrapped in quotes:

{{$_POST.input == 'false'}}

Thanks Teodor. I tried that and it still ignores the condition. No matter what order I put them in, it ignores the "IF’ part of the statement and goes directly to the “Else” part.

So what is your form input exactly? Can you post its code here?
Also are you sure your form method is set to post?

Yes, my form is set to post. It’s pretty simple, here it is.

 <form id="form2" method="post" is="dmx-serverconnect-form" action="../api/IndPay/ClockWorkerIn" dmx-on:success="scListEmployees.load({});scActiveDoorList.load()">
  <input id="WorkStarted" name="workstarted" type="hidden" class="form-control" dmx-bind:value="content.scAppointmentDetails.data.queryAppointmentDetails[0].WorkStarted">
  <input id="ClockInUserID" name="userid" type="hidden" class="form-control" dmx-bind:value="UserID">
  <input id="ClockInLocationID" name="locationid" type="hidden" class="form-control" dmx-bind:value="LocationID">
  <input id="ClockInAppointmentID" name="appointmentid" type="hidden" class="form-control" dmx-bind:value="content.varAppointmentID.value">
  <input id="ClockInModuleID" name="moduleid" type="hidden" class="form-control" dmx-bind:value="varModuleID.value">
    <button type="submit" class="btn btn-clockin btn-block text-xl-left">{{FirstName}} {{LastName}}</button>
 </form>

The flag I’m using for the condition statement is the “workstarted” input. It is coming from MS SQL as a bit field. It comes across in the response payload as false.

Content-Disposition: form-data; name="workstarted"

false

In other usages of bit fields, I have not had to wrap it in quotes, I just use true/false.

Here is my server action with post variables:

Can you please add a setvalue step in your server action and bind the {{$_POST.workstarted}} as a value there, enable output and see the result after the form is submitted in the Network > XHR tab? Post a screenshot of what is displayed there please.

Here is what you asked for, but I got it working. You suggested me to wrap it in quotes:

image

That didn’t work, but when I wrap it in double quotes:

image

Then it worked.

Result:
image

Thanks for your time and pointing me in the right direction.

1 Like