ApplyRules |
This method is used to implement one or more rules. ApplyRules is part of the Methodset Rule Engine 4.2 interface with namespace "http://schemas.cordys.com/ruleengine/4.2".
SOAP Request
<ApplyRules xmlns="http://schemas.cordys.com/ruleengine/4.2"> <objects> <tem:TemplateName xmlns:tem="http://TemplateName"> <tem:Element>1</tem:Element> </tem:TemplateName> </objects> <ruleset> <rule> <ruleid>10000</ruleid> <usexpath>true</usexpath> <metainfo> <namespace> <prefix>tem</prefix> <ns>http://TemplateName</ns> </namespace> </metainfo> <if> <condition>tem:TemplateName/tem:Element = 1</condition> <then> <action> <assignment id="0.597660680694847" name="assignment-s"> <expression> <LHS>tem:TemplateName/tem:Element</LHS> <RHS>"10101"</RHS> </expression> </assignment> </action> </then> </if> </rule> </ruleset> </ApplyRules>
Request Parameters
Parameter |
Description |
Data Type |
Accepted Input Values |
---|---|---|---|
objects |
Contains a set of objects for rule application |
XML |
The ApplyRules SOAP request applies the rule only on the first object that it detects. |
ruleset |
Contains a set of rules to be executed on an object or on a set of objects |
XML |
|
rule |
Defines the rule |
XML |
|
ruleid |
Unique ID for the rule |
String |
This is applicable only if the rules are stored in the CoBOC database. |
usexpath |
Specifies whether the expressions should satisfy xpath compliance |
Boolean |
If usexpath is true, the expression should be XPath compliant. For example: tem:TemplateName/tem:Element. |
metainfo |
Contains the namespace and prefix of the object |
|
|
condition |
Contains expressions that implement the condition |
XML |
|
expression |
Contains the expression that is framed to implement the condition |
|
|
action |
Contains the actions that need to be executed if the condition is satisfied |
|
This element can contain multipleactionelements. |
SOAP Response
<ApplyRulesResponse xmlns="http://schemas.cordys.com/ruleengine/4.2" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <ruleset xmlns="http://schemas.cordys.com/ruleengine/4.2" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <rule status="open"> <ruleid>10000</ruleid> <usexpath>true</usexpath> <metainfo> <namespace> <prefix>tem</prefix> <ns>http://TemplateName</ns> </namespace> </metainfo> <precondition> <expression/> </precondition> <if ruleid="10000"> <condition result="1">tem:TemplateName/tem:Element = 1</condition> <then> <action enabled="true" ruleid="10000"> <assignment id="0.597660680694847" name="assignment-s"> <expression> <LHS>tem:TemplateName/tem:Element</LHS> <RHS>10101</RHS> </expression> </assignment> </action> </then> </if> <visited/> </rule> </ruleset> <objects xmlns="http://schemas.cordys.com/ruleengine/4.2" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <tem:TemplateName xmlns:tem="http://TemplateName"> <tem:Element>10101</tem:Element> </tem:TemplateName> </objects> </ApplyRulesResponse>
Response Parameters
The parameters in the request are reproduced in the response.
Guidelines for Using ApplyRules SOAP Request
Observe the following guidelines while using the ApplyRules SOAP request.
- The ApplyRules SOAP request cannot contain multiple objects of the same type; however, it can have multiple objects of different type as shown in the following sample:
<ApplyRules xmlns="http://schemas.cordys.com/ruleengine/4.2"> <objects> <Order> <ID>07</ID> <item>ABC</item> </Order> <Customer> <ID>008</ID> <name>JOE</name> </Customer> </objects> <ruleset> <rule> <ruleid>5102</ruleid> <if> <condition>Order.item == "ABC"</condition> <then> <action> <assignment> <expression>Order.Price = 100</expression> <expression>Customer.Grade = "Gold"</expression> </assignment> </action> </then> </if> </rule> </ruleset> </ApplyRules> <ApplyRulesResponse xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/ruleengine/4.2"> <ruleset xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/ruleengine/4.2"> <rule status="open"> <ruleid>5102</ruleid> <if ruleid="5102"> <condition result="1">Order.item == "ABC"</condition> <then> <action ruleid="5102" enabled="true"> <assignment> <expression>Order.Price = 100</expression> <expression>Customer.Grade = "Gold"</expression> </assignment> </action> </then> </if> <visited /> </rule> </ruleset> <objects xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/ruleengine/4.2"> <Order> <ID>07</ID> <item>ABC</item> <Price>100</Price> </Order> <Customer> <ID>008</ID> <name>JOE</name> <Grade>Gold</Grade> </Customer> </objects> </ApplyRulesResponse>
- The ApplyRule SOAP request supports nested expression for multiple objects of different type as shown in the following sample:
<ApplyRules xmlns="http://schemas.cordys.com/ruleengine/4.2"> <objects> <Order> <ID>07</ID> <quantity>100</quantity> </Order> <Customer> <ID>008</ID> <name>JOE</name> </Customer> </objects> <ruleset> <rule> <ruleid>5102</ruleid> <if> <condition>Order.quantity &lt;150</condition> <then> <if> <condition>Order.quantity == 100</condition> <then> <action> <assignment> <expression>Order.Price = 200</expression> <expression>Customer.Grade = "Gold"</expression> </assignment> </action> </then> </if> </then> </if> </rule> </ruleset> </ApplyRules> <ApplyRulesResponse xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/ruleengine/4.2"> <ruleset xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/ruleengine/4.2"> <rule status="open"> <ruleid>5102</ruleid> <if ruleid="5102"> <condition result="1">Order.quantity &lt;150</condition> <then> <if> <condition result="1">Order.quantity == 100</condition> <then> <action ruleid="5102" enabled="true"> <assignment> <expression>Order.Price = 200</expression> <expression>Customer.Grade = "Gold"</expression> </assignment> </action> </then> </if> </then> </if> <visited /> </rule> </ruleset> <objects xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.cordys.com/ruleengine/4.2"> <Order> <ID>07</ID> <quantity>100</quantity> <Price>200</Price> </Order> <Customer> <ID>008</ID> <name>JOE</name> <Grade>Gold</Grade> </Customer> </objects> </ApplyRulesResponse>
- If rules are stored in the Rule Repository database, they can be retrieved from the database using the GetRulesByTemplateId SOAP request and can be included in the ruleset in the request. Otherwise, the ruleset must be created by the application as required by the SOAP request.