Author Topic: Rules Custom Constraint  (Read 20577 times)

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Rules Custom Constraint
« on: July 02, 2013, 06:19:33 am »
Emre,

How do you use the Custom Constraint field in Rules?
I need to make a rule execute only if a customer has been selected.
SambaPOS - POS'n the World, one Terminal at a time.

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Rules Custom Constraint
« Reply #1 on: July 02, 2013, 06:46:23 am »
It depends. Which rule is that?

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Re: Rules Custom Constraint
« Reply #2 on: July 02, 2013, 07:21:26 am »
Order Added to Ticket.

I am working on cash discounts based on the item/item group selected but only if a customer has been selected. So I need to check the value of a variable I created with Update System Settings.
SambaPOS - POS'n the World, one Terminal at a time.

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Rules Custom Constraint
« Reply #3 on: July 02, 2013, 07:38:09 am »
You can use it on custom constraint area like

{:MySetting} == 1

Rule executes if MySetting equals 1;

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Rules Custom Constraint
« Reply #4 on: July 02, 2013, 07:40:50 am »
Another Alternative might be using Ticket States

Ticket.IsInState("Promotion")

Rule executes if Any ticket state have Promotion Value.

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Re: Rules Custom Constraint
« Reply #5 on: July 02, 2013, 07:49:25 am »
That's the only thing I didn't try ==

Thx Emre
SambaPOS - POS'n the World, one Terminal at a time.

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Re: Rules Custom Constraint
« Reply #6 on: July 02, 2013, 09:38:37 am »
You can use it on custom constraint area like

{:MySetting} == 1

Rule executes if MySetting equals 1;

What about strings? Do we need to enclose them in quotes?
SambaPOS - POS'n the World, one Terminal at a time.

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Re: Rules Custom Constraint
« Reply #7 on: July 02, 2013, 10:28:17 am »
Another Alternative might be using Ticket States

Ticket.IsInState("Promotion")

Rule executes if Any ticket state have Promotion Value.

And now I can't get this working.
I have set the Ticket State to Member: Discount when a customer is selected - This works.
The rule for applying item discounts has Ticket.IsInState("Discount") set as the Custom Constraint and the rule executes whether a customer has been selected or not.
SambaPOS - POS'n the World, one Terminal at a time.

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Rules Custom Constraint
« Reply #8 on: July 02, 2013, 01:08:06 pm »
Let me test that. I'll be back.

Edit: Which rule are you using to apply item discounts?

Edit 2: I've tested it and it works fine for me. There might be two reasons.

1. There might be a typo. Check Trailing spaces.
2. Not every rules can access Ticket info. You can access Ticket data from rules related with tickets like "Ticket Closed, Ticket Created, Order Added, etc."
« Last Edit: July 02, 2013, 01:24:04 pm by emre »

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Rules Custom Constraint
« Reply #9 on: July 02, 2013, 01:16:03 pm »
You can use it on custom constraint area like

{:MySetting} == 1

Rule executes if MySetting equals 1;

What about strings? Do we need to enclose them in quotes?

It should be:

"{:MySetting}" == "Blah"

That means we should enclose both parts.

When you have free time check http://fluentscript.codeplex.com/documentation. We are using it as the Expression Evaluator :)

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Re: Rules Custom Constraint
« Reply #10 on: July 02, 2013, 03:23:52 pm »
1. There might be a typo. Check Trailing spaces.
Done.
2. Not every rules can access Ticket info. You can access Ticket data from rules related with tickets like "Ticket Closed, Ticket Created, Order Added, etc."
Rule I'm using is Order Added to Ticket

The process is

Customer is selected
- Update Ticket State, Statename Member, State Discount

- Order Added to Ticket, Constraint Ticket.IsInState("Discount"), and MenuItemGroupCode matches, give $ discount & tag item as discounted
SambaPOS - POS'n the World, one Terminal at a time.

JohnS

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 677
Re: Rules Custom Constraint
« Reply #11 on: July 28, 2013, 09:36:22 am »
Emre,

I still don't get what I'm doing wrong here.

I can set a Ticket State when I select a Member -> Discount: Member
But I cannot use - Ticket.IsInState("Member") as a constraint. The Rule always executes even when no Member has been selected.

What am I missing?
SambaPOS - POS'n the World, one Terminal at a time.

emre

  • SambaPOS Developer
  • Samba Team
  • Hero Member
  • *****
  • Posts: 1564
Re: Rules Custom Constraint
« Reply #12 on: July 29, 2013, 04:59:00 am »
My bad. It looks like our script engine does not support overloaded methods. On next release it should work.
You'll be able to use:

Ticket.InState(StateName,State)
or
Ticket.IsInState(State)