Condition problem with inline flows

Hi,

I have an IF condition where I perform a check in the data store to ensure a value has not been entered already.

Originally the line read the following;

(serverconnectform1.strCardProxy.value != datastore_cards.data[0].card)

So this would seem to only check against the first record in the datastore and I guess it’s because of the [0]?

So I removed the [0] so that the line reads the following;

(serverconnectform1.strCardProxy.value != datastore_cards.data.card)

This however then does not perform the check at all.

How do I check that the value entered onto the input does not exist in any of the rows in the datastore?

Thanks,
Ray.

Hello Ray,
You cannot just remove the [0] and expect this to work :slight_smile:
(Mentioning @TomD here to show him just one of the many many many reasons we are trying to minimize code editing possibilities with the new expressions builder.)

Here you need to use the where formatter applied on the datastore data element and check if it has items.
So it should be:

Hi @Teodor,

I have tried to implement the change you suggested, however now the IF condition does nothing now.

I get an error in the console.

Ray.

First of all - is that an inline flow? Then - when it needs to run exactly?
Also - did you pick the card property using the data picker and why did you use the toNumber formatter?

And can you paste the expression generated for the condition here (copy it from code view) - so i can check it?

Hi,

I believe its an inline flow and the condition is the very first check.

I check to see if the value of the “Card” already exist and if it does, the condition should run the “ELSE” otherwise I contiue to the next condition.

I used the toNumber as the value input was set to text and the value in the data store is set to number.

This is the IF condition.

`datastore_cards.data.where(`card`, serverconnectform1.strCardProxy.value.toNumber(), "==").hasItems()`

This is the dmx-on:Submit

dmx-on:submit="run({condition:{if:`datastore_cards.data.where(\\`card\\`, serverconnectform1.strCardProxy.value.toNumber(), &quot;==&quot;).hasItems()`,then:{steps:{condition:{if:`serverconnect_availablefunds.data.query_value`,then:{steps:{condition:{if:`((datastore_cards.data.sum(\'cardvalue\') + serverconnectform1.strValue.value.toNumber()) <= serverconnect_availablefunds.data.query_value.mAvailableFunds)`,then:{steps:[{run:{action:`datastore_cards.insert({card: strCardProxy.value, name: strCardName.value, reason: strReason.value, notes: strNotes.value, value: strValue.value, id: datastore_cards.data[0].$id, cardvalue: strValue.value})`}},{run:{action:`serverconnectform1.reset()`}},{run:{action:`strCardProxy.focus()`}}]},else:{steps:{'bootbox.alert':{message:'You don\'t have enough funds on  account.',title:'Not Enough Funds',buttons:{ok:{className:'btn-danger'}}}}}}}},else:{steps:[{run:{action:`datastore_cards.insert({card: strCardProxy.value, name: strCardName.value, reason: strReason.value, notes: strNotes.value, value: strValue.value, id: datastore_cards.data[0].$id, cardvalue: strValue.value})`}},{run:{action:`serverconnectform1.reset()`}},{run:{action:`strCardProxy.focus()`}}]}}}},else:{steps:{'bootbox.alert':{message:'The card number is already in your list of cards to be activated. Please check the number again.',title:'Card Already in List ',buttons:{ok:{className:'btn-danger'}}}}}}})"

That’s quite a complex flow for using it inline.
Please build it as a regular flow and just call it on the event you need it. Meanwhile we are going to check the code generated by the inline flow.

So, just add your flow in the app connect and define it there. Then on form submit call the flow you created.

I appreciate why you’re doing this and don’t disagree with it. As I wrote, I hope you would find a solution …

However the recent changes to restrict direct editing will make some work with Wappler much more time-consuming. Perhaps a solution would be to add the editing option you have provided for variables to other expressions, so users could choose. Eg if I wanted to change ‘4’ to ‘5’:

image

I could perform a series of clicks and type ‘5’ or click the pencil icon and type ‘5’:

image

Offering both options is very helpful - choosing from the pickers and formatters may be sufficient, or it can be used in combination with manual editing (as in the example above). Is there any reason why these options are not available for Conditions for example? With complicated conditions the situation become much worse - a bit like typing an email by clicking on a virtual keyboard.

So if I understand correctly, create the flow control in the App Connect and then on Submit of the form call the flow from the App Connect?

I have done and the condition acts as now expected. Here is the App Connect Flow.

	    <script is="dmx-flow" id="flow_addcard" type="text/dmx-flow">{
  condition: {
    if: "{{data_view_datastore_cards.data.where(`card`, serverconnectform1.strCardProxy.value, \"==\").hasItems()}}",
    then: {
      steps: {
        bootbox.alert: {
          message: "The card number is already in your list of cards to be activated. Please check the number again.",
          title: "Card Already in List",
          buttons: {
            ok: {className: "btn-danger"}
          }
        }
      }
    },
    else: {
      steps: {
        condition: {
          if: "{{serverconnect_availablefunds.data.query_value.mAvailableFunds}}",
          then: {
            steps: {
              condition: {
                if: "{{((datastore_cards.data.sum('cardvalue') + serverconnectform1.strValue.value.toNumber()) <= serverconnect_availablefunds.data.query_value.mAvailableFunds)}}",
                then: {
                  steps: {
                    run: {
                      action: "{{datastore_cards.insert({card: serverconnectform1.strCardProxy.value, name: serverconnectform1.strCardName.value, reason: serverconnectform1.strReason.value, notes: serverconnectform1.strNotes.value, cardvalue: serverconnectform1.strValue.value, value: serverconnectform1.strValue.value});serverconnectform1.reset();serverconnectform1.strCardProxy.focus()}}",
                      name: "insert_into_datastore_enoughfunds",
                      output: true
                    }
                  }
                },
                else: {
                  steps: {
                    bootbox.alert: {
                      message: "You don't have enough funds on  account.",
                      title: "Not Enough Funds",
                      buttons: {
                        ok: {className: "btn-danger"}
                      }
                    }
                  }
                }
              }
            }
          },
          else: {
            steps: {
              run: {
                action: "{{datastore_cards.insert({card: serverconnectform1.strCardProxy.value, name: serverconnectform1.strCardName.value, reason: serverconnectform1.strReason.value, notes: serverconnectform1.strNotes.value, cardvalue: serverconnectform1.strValue.value, value: serverconnectform1.strValue.value});serverconnectform1.reset();serverconnectform1.strCardProxy.focus()}}",
                name: "Insert_into_datastore",
                output: true
              }
            }
          }
        }
      }
    }
  }
}</script>

This might help when compared to my inline to see what I have done wrong.

Thanks,
Ray

Yes, just select Flow > run on the event you need.

It’s not your fault actually. There seems to be a small issue with the inline flows , but @George will take care of it :slight_smile:

1 Like

Super thanks, but I think i might stick with the App Connect Flow as its much easier to read in code view.

Are there any benefits to running in inline over App Connect?

Well if it’s something small used on one button only it’s fine to use the inline option.
I personally prefer the Flow component in App Connect, especially for more complex flows or for flows used multiple times.

1 Like

This has been fixed in Wappler 2.8.4

1 Like

This topic was automatically closed after 45 hours. New replies are no longer allowed.