Skip to content

Parse

Parses the input and returns a function that can be used to execute the decision table.

1
$Decisions.Parse(input: ( string | Xml )):(input: any) => any

Parameters

( string | Xml ) input
    An XML node instance or a decision table XML string.

Returns

A function that can be used to evaluate data against the decision table.

Remarks

Parsing accepts only an XML string or Xml. Calling the returned function accepts an object, an XML node, or no input. null decision output is mapped to JavaScript undefined; identities, dates, arrays, and scalar values are converted to their scripting equivalents.

Examples

Sample decision table XML

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  <MyDecisionTable HitPolicy="Any" Aggregation="">
    <OutputLabel>Discount by Customer Category</OutputLabel>
    <Inputs>
      <Input>
        <Label>Customer Category</Label>
        <Expression TypeRef="string">Customer.Category</Expression>
        <InputValues TypeRef="" />
      </Input>
      <Input>
        <Label>Order Size</Label>
        <Expression TypeRef="number">OrderSize</Expression>
        <InputValues TypeRef="" />
      </Input>
    </Inputs>
    <Outputs>
      <Output TypeRef="number" Name="Discount">
        <Label>Discount</Label>
        <OutputValues />
        <Default>0</Default>
      </Output>
    </Outputs>
    <Rules>
      <Rule>
        <Description />
        <Inputs>
          <Input>"Business"</Input>
          <Input><10</Input>
        </Inputs>
        <Outputs>
          <Output>0.10</Output>
        </Outputs>
      </Rule>
      <Rule>
        <Description />
        <Inputs>
          <Input>"Business"</Input>
          <Input>>=10</Input>
        </Inputs>
        <Outputs>
          <Output>0.15</Output>
        </Outputs>
      </Rule>
      <Rule>
        <Description />
        <Inputs>
          <Input>"Private"</Input>
          <Input />
        </Inputs>
        <Outputs>
          <Output>0.05</Output>
        </Outputs>
      </Rule>
    </Rules>
  </MyDecisionTable>

Evaluate a decision table with an object

1
2
3
4
5
6
var discount = $Decisions.Parse($Xml.SelectSingle('MyDecisionTable'));

var result = discount({
    CustomerCategory : 'Business',
    OrderSize : 10
});

Evaluate a decision table with form data

1
2
3
4
var discount = $Decisions.Parse($Xml.SelectSingle('MyDecisionTable'));

// input values are read from the child elements of the node
var result = discount($Xml.SelectSingle('Order'));

See Also