I have Simple Rule in which i have insert two String type of variable in Session. now i need to fetch variables.
Code For same:
rule "Header Account Null Check"
dialect "java"
ruleflow-group "TB:Header Account Null Check"
when
cAccount : AccountPair( headerAccount == null )
then
String error=new String();
String validateMsg=new String();
error="2528";
validationMsg="Header Account must not be null"
modify( cAccount ) {
setErrorCode( "2528" )
}
insert(error);
insert(validateMsg);
System.out.println("Header Account null check called");
end
query "fetch validation variables"
#conditions
s:String();
end
Java Code:
Collection<Object> myfacts = kSession.getObjects( new ClassObjectFilter(String.class) );
After checking in myfacts i got two values.
Now the problem is there are two variables with String.class Type, I need to know which value is for error and which value is for validationMsg so that we will perform next task.
Same with Input also if we add two String variable from Session now i need to add condition on those variable. so same problem also occur for same.till now we resolved input variable problem by declaring variable as a Global Variable. I also need to change this strategy because its not a good decision for declaring global variable.
Please help me out.
This should be pretty obvious: if you have several String objects you cannot distinguish unless their values have certain characteristics. (In your case, the error string is numeric and the other one not.) But basing an app on this is not recommended.
So you must attach an identification to the String value. For this, you can create an object containing a String name
and a String value
. And your RHS becomes:
insert( new Result( "error", "2528" ) );
insert( new Result( "message", "Header Account must not be null" ) );
modify( cAccount ) {
setErrorCode( "2528" )
}
System.out.println("Header Account null check called");
You can use the same principle for multiple inputs.