Skip to content

Parse

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

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

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.

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 an XML Node object to evaluate

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

See Also