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 )):DecisionTable

Parameters

( string | Xml ) input
    Xml node instance or decision table xml string

Remarks

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>

Parsing decision table xml

1
2
var decisionTableNode = $Xml.SelectSingle('MyDecisionTable');
var fn = $Decisions.Parse(decisionTableNode);

Providing JSON to evaluate

1
2
3
4
var result = fn({
    CustomerCategory: "Business",
    OrderSize: 10
});

Providing XML Node object to evaluate

1
2
var dataNode = $Xml.SelectSingle('MyDataInputs');
var result = fn(dataNode);