Skip to content

Evaluating an array of Facts #251

@brent-hoover

Description

@brent-hoover

I am looking to evaluate an array of facts to see if any member of the array meets multiple conditions. So far I have not been able to figure out how to do it and wondering if it is possible or if I am barking up the wrong tree.

Here's my example:

const facts = {
	customerName: "Dave Smith",
	totalsPerBrand: [
		{
			name: "levis",
			total: 120
		},
		{
			name: "versace",
			total: 1
		}

	]
};

engine.addRule({
  conditions: {
    any: [{
      all: [
      {
        fact: 'totalsPerBrand',
        path: '$.[*].name',
        operator: 'equal',
        value: "versace"
      },
      {
        fact: 'totalsPerBrand',
        path: '$.[*].total',
        operator: 'equal',
        value: 120
      },

     ]
    }]
  },
  event: {  // define the event to fire when the conditions evaluate truthy
    type: 'awardOffer',
    params: {
      message: 'Offer is Awarded'
    }
  }
})

Here I want to rule to evaluate true if, for any member of the array both name = "levis" and total > 100. I can't use equal because my path evaluates to an array and I can't use contains because that means if any member satisfies either of the conditions it will evaluate to true.

Anybody have any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions