Add 'Selected Orders Count' Constraint on a Rule

I would like to add a constraint to check the number of selected orders equals 1 before running an action (if there is more than 1 my action causes SambaPos to crash).

I have tried:

I have also tried many other things(!) but cant get the right syntax for this to work. The rule and action works fine otherwise. Please can someone tell me the correct constraint to use. Thanks!

Not sure if the {SELECTED ORDERS COUNT} is valid. Try {SELECTED ORDER COUNT} please note without ‘S’.

Or use [=TN ('{SELECTED ORDERS}')] Greater 0. If more than 1 selected the value will contain comma separate value. It should return 0 when convert to number. Unless TN is too smart to get rid of it :slight_smile:

If then using indexOf it check if there is comma.

1 Like

Thats the correct tag and ive used it as is and it works fine, ive not needed to add the TN expression bits

Thanks for your replies. I have tried both variations and still cant get it working.
As I understand it {SELECTED ORDERS} will return a string of orders selected. What I need to know is how many there are selected (or if there is just one selected).

I have tried {SELECTED ORDER COUNT} which never fires the action so assuming it isnt a valid constraint

and [=TN (’{SELECTED ORDERS}’)] Greater 0 - this always fires the action even if I have 2 orders selected (and crashes the program).

Is there a list of valid constraints documented somewhere that I can look at?

Any help appreciated…Thanks!

Most {} tags are listed in printer template help.
What you want to do is add an ask question or show message action and for the question/message put in your {} expressions your testing so you can see what they are returning.

That’s what Ive just worked out and it is showing me that the {SELECTED ORDERS} is the only thing returning anything. If I select 2 orders this returns 2 numbers separated by a comma. So is there a way of counting commas - a string finding command?

Sorry Im still very new to SambaPOS…

Using this [='{SELECTED ORDERS}'.indexOf(',')] Less than 0

BTW, TN does remove comma before it try to convert to number.

3 Likes

You would probably need to +1 as a single selected order would have no comma and 2 only 1
Alternative would be to parse the list and use .length on the array created in scripts.

indexOf return -1 if not found any match.

1 Like

Either way Isn’t index of just giving the position of the first one found??

Yes, it does. But he only need condition that has no comma at all.

This works perfectly - thanks for your help! I can now only apply the action to the first selected order which is what I needed.