Assume that I have two data objects Person and Address. Person object has the fields name and gender and Address object has the fields city and state. Now I want to take some action based on this condition :
when
(person.name == 'jayram' && address.city == 'barhiya') ||
(person.gender == 'M' && address.state == 'bihar')
then
do something
How to accomplish this in drools rule file?
Maybe this should be the solution:
package com.sample
dialect "mvel"
import com.sample.Person;
import com.sample.Address;
rule "Hello World"
when
person : Person( status == Message.HELLO)
Address((person.name == 'jayram' && city == 'barhiya') ||
(person.gender == 'M' && state == 'bihar'))
then
// Do something
end
Related
I have created two different rules, which belong to two different agenda-groups.
First one:
rule "32-30-33.32"
dialect "java"
salience 0
agenda-group "32-30"
when
map : Map((this["Product Name"].toUpperCase().contains("PREMIUM ADPRODUCT")) && ((this["Size Length"] != 5) || (this["Size"].toUpperCase() not contains "300X600") || (this["Size"].toUpperCase() not contains "280X130") || (this["Size"].toUpperCase() not contains "300X250") || (this["Size"].toUpperCase() not contains "970X250") || (this["Size"].toUpperCase() not contains "320X50")));
then
JSONObject jObject = new JSONObject("{\"error34\":\"Premium Adproduct doesn't contain required Creative size!\"}");
Iterator<?> keys = jObject.keys();
while(keys.hasNext()) {
String key = (String)keys.next();
Object value = jObject.get(key);
map.put(key, value);
}
debug(drools);
end
Another rule, in another agenda group:
rule "47-37-1.0"
dialect "java"
salience 0
agenda-group "47-37"
when
map : Map((this["OrderName"] == null));
then
JSONObject jObject = new JSONObject("{\"error1\":\"OrderName should not be null \"}");
Iterator<?> keys = jObject.keys();
while(keys.hasNext()) {
String key = (String)keys.next();
Object value = jObject.get(key);
map.put(key, value);
}
debug(drools);
end
After this, I set focus to the group "47-37",
kieSession.getAgenda().getAgendaGroup("47-37").setFocus();
All rules within the group "32-30" are also getting evaluated. I'm using Drools 7.0.0. How can I control execution of rules only within the focused group?
I have an ion-select where on change, I need to update values in other ion-select that is related.
The first ion-select is for selecting countries, then according to the specified one, the second ion-select will display the related major cities.
The problem that is cities displayed are always the one of the following array: kuwait_ar except of the country of Kuwait , where the cities are the correct ones kuwait_en.
Here is a stackblitz.
Here is the code for (ionChange):
displayCities()
{
let country = this.formGroup.controls.country.value;
this.cityArray = [];
//console.log(country)
this.cityArray = ((country == "Bahrain" || country == "البحرين") && this.lang=="en")?this.bahrain_cities_en:this.bahrain_cities_ar;
this.cityArray = ((country == "Oman" || country == "عمان") && this.lang=="en")?this.oman_cities_en:this.oman_cities_ar;
this.cityArray = ((country == "Qatar" || country == "قطر") && this.lang=="en")?this.qatar_cities_en:this.qatar_cities_ar;
this.cityArray = ((country == "Saudi Arabia" || country == "المملكة العربية السعودية") && this.lang=="en")?this.ksa_cities_en:this.ksa_cities_ar;
this.cityArray = ((country == "UAE" || country == "الامارات العربية المتحدة") && this.lang=="en")?this.uae_cities_en:this.uae_cities_ar;
this.cityArray = ((country == "Kuwait" || country == "الكويت") && this.lang=="en")?this.kuwait_cities_en:this.kuwait_cities_ar;
//console.log(this.cityArray)
}
Your problem is happening because you are assigning this.cityArray multiple times. The reason "Kuwait" works correctly, is because it is the last one in the list.
Consider when you select "Bahrain":
#1 this.cityArray = ((country == "Bahrain" || country == "البحرين") && this.lang=="en")?this.bahrain_cities_en:this.bahrain_cities_ar;
#2 this.cityArray = ((country == "Oman" || country == "عمان") && this.lang=="en")?this.oman_cities_en:this.oman_cities_ar;
#3 this.cityArray = ((country == "Qatar" || country == "قطر") && this.lang=="en")?this.qatar_cities_en:this.qatar_cities_ar;
#4 this.cityArray = ((country == "Saudi Arabia" || country == "المملكة العربية السعودية") && this.lang=="en")?this.ksa_cities_en:this.ksa_cities_ar;
#5 this.cityArray = ((country == "UAE" || country == "الامارات العربية المتحدة") && this.lang=="en")?this.uae_cities_en:this.uae_cities_ar;
#6 this.cityArray = ((country == "Kuwait" || country == "الكويت") && this.lang=="en")?this.kuwait_cities_en:this.kuwait_cities_ar;
Line #1 correctly sets this.cityArray = this.bahrain_cities_er because your condition (country == "Bahrain" evaluates to true AND this.lang is set to "en"... GOOD
But... Line #2, (country == "Oman" || country == "عمان") evaluates to false, so your are reassigning the value of this.cityArray = this.oman_cities_ar
The same goes for Line #3-#6, thus the last line assigns it to this.kuwait_cities_ar as you have experienced.
Perhaps a switch statement would work better when only once case gets executed.
However, your approach is very complicated. You could structure your definitions of country/city names in a nested array or map, so you can simply "look up" the correct list, rather than "figure it out" based on a selected value. You could also two separate lists, one for each language, then simply swap them out based on the current language.
I'm using an external filter in ag-grid which is supposed to filter the records based on a select value dropdown which has values corresponding to a specific field in the grid.
And I'm unable to access the value of the field using node.data.fieldName as mentioned in the documentation here.
Below is what I'm doing:
function isExternalFilterPresent() {
return $scope.filterval.ReleaseType!='All' && $scope.filterval.ReleaseType!='';
}
function doesExternalFilterPass(){
console.log('$scope.filterval.ReleaseType : ' ,$scope.filterval.ReleaseType);
if($scope.filterval.ReleaseType == 'A'){return node.data.ReleaseType = 'A';}
if($scope.filterval.ReleaseType == 'B'){}
if($scope.filterval.ReleaseType == 'C'){}
if($scope.filterval.ReleaseType == 'D'){}
if($scope.filterval.ReleaseType == 'D'){}
}
It throws an error : node is not defined
When I try using just data.fieldName it says 'data is not defined'
Can someone please help me understand how I can access the value of the specific field here.
You need to provide node as an argument to the function. ag-grid calls this function with appropriate argument node.
Link: Example External filter
function doesExternalFilterPass(node) { // <- node as argument
console.log('$scope.filterval.ReleaseType : ' ,$scope.filterval.ReleaseType);
if($scope.filterval.ReleaseType == 'A'){return node.data.ReleaseType = 'A';}
if($scope.filterval.ReleaseType == 'B'){}
if($scope.filterval.ReleaseType == 'C'){}
if($scope.filterval.ReleaseType == 'D'){}
if($scope.filterval.ReleaseType == 'D'){}
}
I have custom obj "A" and Standard obj Case. Case standard obj has lookup to custom obj "A". there is a field between the two objects called Customer_ID__c. I wrote a Trigger (before Insert, Before Update) to associated the case record to the correct existing custom obj "A" record if "Case.Custom_Id__c" match the one in the Custom obj "A". Unfortunate it is not happening and I'm not sure where to look.
trigger IAACaseRelateASAP on Case (before insert, before update) {
Id recordtypes = [Select Id, name
From RecordType
Where SobjectType = 'Case'
AND Name = 'I Buy'
LIMIT 1].Id;
Set<String> casId = new Set<String>();
for(Case cs : Trigger.new)
{
if(cs.RecordtypeId == recordtypes && cs.Type == 'Contact Me')
{
if(cs.custm_Obj_A_Name__lookupfield__c == null && (cs.Customer_ID__c != null || cs.Customer_ID__c !='0'))
{
casId.add(cs.Customer_ID__c);
}
}
}
system.debug('Case Set Ids' + casId);
List<A__c> aList = [Select Customer_ID__c, Id
From A__c
Where Customer_ID__c IN: casId
AND
A__c != 'Provider'];
System.Debug('equals' + aList);
Map<String, A__c> aMapId = new Map<String, A__c>();
for(A__c aAcct : aList)
{
aMapId.put(aAcct.Customer_ID__c, aAcct);
}
for(Case cas : Trigger.new)
{
if(cas.RecordtypeId == recordtypes && cas.Type == 'Contact Me')
{
if(cas.custm_Obj_A_Name__lookupfield__c == null && (cas.Customer_ID__c != null || cas.Customer_ID__c !='0'))
{
if(aMapId.containsKey(cas.Customer_ID__c))
{
A__c aAcct = aMapId.get(cas.Customer_ID__c);
System.Debug('Case IAA ASAP Account value: ' + asapAcct);
}
}
}
}
}
It might be best when looping through your cases to build your set of Customer_ID__c ids to also build a List of cases with customer ids so that you don't have to loop through the entire new list a second time. There are a couple other issues with the trigger in general but I'll ignore those and just focus on what you asked. Think your issue is that you don't actually set the case field in this area:
if(aMapId.containsKey(cas.Customer_ID__c))
{
A__c aAcct = aMapId.get(cas.Customer_ID__c);
System.Debug('Case IAA ASAP Account value: ' + asapAcct);
}
It should be :
if(aMapId.containsKey(cas.Customer_ID__c))
{
cas.custm_Obj_A_Name__lookupfield__c = aMapId.get(cas.Customer_ID__c).Id;
}
using (WinFileContextContainer c = new WinFileContextContainer())
{
IQueryable<File> dbfiles = (from f in c.File
where //(f.Category.Any((category => category.name == categoryname)) &&
f.alive //&&
//f.description == "" &&
//f.Category.Count == 1)
select f);
// the rest....
}
The query works only as it is now - I left just one criteria (the rest is in comment sections). But I want the other criteria to be taken into account too. I tried with multiple "where"s :D or all the criteria in brackets with one "where", but still no success. I'm kinda new to LINQ so any help is appreciated. Thanks in advance !
Finally got it to work:
IQueryable<File> dbfiles =
c.File.Where(f => f.Category.Any(cat => cat.name == categoryname) &&
f.alive &&
f.description == null &&
f.Category.Count == 1);