how to make a workflow flow based on different rules - email

I am attempting to create a workflow rule but am running into syntax errors. I would like the workflow to fire if the record type is equal to "Athlete", "Coach", or "Judge", the Profile Status is equal to "Active", and the Medical Exam Date is equal to today. This is what I have so far:
IF
(AND(RecordType.Name == 'Athlete',Profile_r.Status_c == 'Active') , TODAY() = Medical_Exame_Date)
Thanks

There are few cases where you would need to use an IF(condition, iftrue, iffalse) in a workflow. When the workflow is evaluated, it's just looking for the entire condition to return true or false. I think this may be what you're looking for:
AND(
OR(
RecordType.Name == 'Athlete',
RecordType.Name == 'Coach',
RecordType.Name == 'Judge'
),
Profile__r.Status__c == 'Active',
Medical_Exame_Date__c == TODAY()
)

Related

Ag-grid valueFormatter and Column Filter

I am having problems using ag-grid valueFormatter and column filters (https://www.ag-grid.com/javascript-data-grid/filtering/).
I have a simple colDef:
{
headerName: 'My column',
field: 'myData',
hide: true,
valueFormatter: this.formatterBooleanToHuman,
},
the formatterBooleanToHuman is a simple code to change true to Yes and false to No.
It works as expected, the issue is that we are using column filters, and when I click on the filter I have true and false to select, if I select any of them, nothing returns from the filters because the value now is actually Yes and No.
I couldn't manage to have both of them working together. To have the column filter working properly I need to remove the valueFormatter, but I would like to have both working.
I tried to apply the valueFormatter function to filterParams.valueFormatter, it did change the values on the filter but something is failing, I am getting 2 No and 1 Yes, and none of them filter.
Any suggestions?
UPDATE:
So, I found a solution, but I am not convinced it is the right way to do it.
get getcolumnDef(): Array<ColDef> {
return [
{
headerName: 'Boolean Column',
field: 'booleanValue',
hide: true,
valueFormatter: this.formatterBooleanToHuman,
filterParams: {
valueGetter: (params) => this.filterBooleanValueGetter(params, 'booleanValue')
}
}
];
}
private filterBooleanValueGetter(params: ValueGetterParams, propertyName: string) {
let isDeleted = false;
const hasValue = !!params && !!params.data && params.data[propertyName];
if (hasValue) {
isDeleted = String(params.data[propertyName]) === 'true';
}
return isDeleted ? 'Yes' : 'No';
}
So, the valueGetter works as expected and makes my filter work, I just think it is a bit "dirty" to have it to work like that, I haven't found anything on the docs saying this is the way it needs to be done. So suggestions are more than welcome.
valueFormatter applies only to data in grid. However even if the filter shows true and false instead of formatted values, it should work correctly. If filtering does not work, it may indicate some other error in your code. Maybe you depend on this in formatterBooleanToHuman method?
Anyway to format values in filter, you should define filterParams.valueFormatter like this:
{
// ...
valueFormatter: this.formatterBooleanToHuman,
filterParams: {
valueFormatter: this.formatterBooleanToHuman
}
}
For some reason, the value given to filter formatter is string instead of boolean (bug in ag-grid?), you need to adjust that.
See complete example here: https://plnkr.co/edit/o3sN3GodqQumVe09

What does a drools fact check (when) return when one uses the "in" operator

I have the following rule
rule One
when
vg1 : Vgdoc(code() in ("IA1003", "IA1004"), colour == "red")
then
.. do something with vg1
end
when I use the vg1 in the then clause I see that it represents one object but what if both ("IA1003", "IA1004") exists? does drools only send the first one or both? and if it sends both how can I check it.
Is it possible to do something like this to
vglist : List() from collect (Vgdok(code() in ("IA1003", "IA1004")))
will this list contain both fact if they exists in the memory?
cheers
es
Your rule will hit for each item in working memory that matches.
Simplifying things, let's say that your model looks like this:
class Vgdoc {
public String getCode() { ... }
public String getColour() { ... }
}
And your rule is like what you have, syntax corrected:
rule "One"
when
vg1: Vgdoc( code in ("IA1003", "IA1004"),
colour == "red" )
then
Systen.out.println("Rule 1 fired");
end
And you have objects in working memory:
Vgdoc{ code: "IA1003", colour: "red" } // A
Vgdoc{ code: "IA1004", colour: "red" } // B
Vgdoc{ code: "IA1005", colour: "red" } // C
Vgdoc{ code: "IA1003", colour: "blue" } // D
Then your rule will fire twice, once for the item I commented as "A" and once for the item I commented as "B". (Eg. there will be two instances of Rule 1 fired printed.) It will not fire for item commented "C" because the code does not match, and it will not fire for item commented "D" because the colour field does not match.
Now, if you want to only fire once and to do something with the collection of all Vgdoc matching the condition (color 'red' and code 'IA1003' or 'IA1004'), then yes you'd use a collect. Something like this:
rule "IA1003 and IA1004 with red"
when
vgList: List() from collect( Vgdoc( code in ("IA1003", "IA1004"), colour == "red" ))
then
System.out.println("Rule fired, match count: " + vgList.size());
// vgList will contain all items that match the conditions for code and colour
end
This version of the rule, with the same inputs from before, will fire exactly once and will print: Rule fired, match count: 2.
Which one you choose to use depends on your use case.

ag - grid + angular 4 custom text filter

I have a column called Account Verification which return values either true or false. I formatted the value on table to Yes and No, but when filtering the column, I still have to search true or false to be able to filter the column. I made a custom filter condition but it did not work. Anyone has solution?
columns = [
{
headerName: 'Account Verification', field: 'accountVerified', filter: 'agTextColumnFilter',
// Cell renderer
valueFormatter: (data) => {
if (data.value === true) return 'Yes';
else return 'No';
},
// Custom filter
filterParams: {
condition: (searchTerm, cellValue) => {
if (searchTerm === 'Yes' || 'yes') {
return cellValue === true;
} else if (searchTerm === 'No' || 'no') {
return cellValue === true;
} else return cellValue === null;
}
}
}
]
"ag-grid": "^18.0.1"
I think the best way to implement this - is to use built in methods of ag-grid, like:
onFilterModified
onFilterChanged
And there provide the logic, which would be transform the filter value to true/false.
Or, use javascript to add event listener on apply button of the filter (if you are using apply button to apply your filter), which would call fucntion for transform your value.
Have no example in the moment, but I develped solution for filter validation (custom) in the same way.
Try one of these options:
Similar to to valueFormatter in your column definition, use a valueGetter also. There is also this method available in column definition (filterValueGetter(params) - Function or expression. Gets the value for filtering purposes.)
You can add a new field in your data model that you initialize to Yes/No based on the values of the original field that has true/false. Then in the column definitions, you can use this new field to display in the grid.
Alternatively, you can write a custom filter component. See the custom Angular filter example on the ag-grid site.
You can use TextFormatter within the filterParams to modify the filter value during filtering:
filterParams: { textFormatter: (filterValue) => 'yourvalueformatter' }
https://www.ag-grid.com/javascript-grid-filter-text/#text-formatter
I had the same issue and went through all the inbuilt filters.
Finally I was able to fix the issue by following the below steps
Steps :
Install the ag-grid-enterprise package. (npm install ag-grid-enterprise)
Set the filter to agSetColumnFilter. (filter: 'agSetColumnFilter')
Add filterParams and specify the same valueFormatter which you used in the column definition
filterParams: {
   valueFormatter: (data) => {
       if (data.value === true) return 'Yes';
       else return 'No';
      }
}
You can try adding this to your column definition:
filterValueGetter: params => params.data.accountVerified ? "Yes" :
"No"

Drools : Rule Formation - One Rule output should trigger other Rules

I am fairly new to Drools and getting my head around it.
Scenario:
rule A output -> should trigger Rule b , Rule c and send then get the final output etc
Example : For simplification
CountryBean --> { String isdCode ,List<String> tates}
rule "Get States by Country's ISD Code"
no-loop true
when country: Country(isCode=="+1")
then
country.setStates("Kentucky" , "North Carolina"....);
update(country);
StateBean --> {String state,String population}
rule "Get Population of States"
no-loop true
when state: States(state !="", $state=state)
then
if(state=="Kentucky")
state.population("1M");
update(state)
My Solution
Execute the first Rule
then iterate over the states and execute States rules
Country country = new Country("+1");
ksession.insert(country )
ksession.fireAllRules();
List<States> stateList=new ArrayList<States>();
country.getStates().forEach(state-> {
ksession.insert(new State(state));
ksession.fireAllRules();stateList.add(state);
});
I dont think this is the right way to do it. How should I approach this problem ?

Spark SQL filter multiple fields

What is the corrent syntax for filtering on multiple columns in the Scala API? If I want to do something like this:
dataFrame.filter($"col01" === "something" && $"col02" === "something else")
or
dataFrame.filter($"col01" === "something" || $"col02" === "something else")
EDIT:
This is what my original code looks like. Everything comes in as a string.
df.select($"userID" as "user", $"itemID" as "item", $"quantity" cast("int"), $"price" cast("float"), $"discount" cast ("float"), sqlf.substring($"datetime", 0, 10) as "date", $"group")
.filter($"item" !== "" && $"group" !== "-1")
I think i see what the issue is. For some reason, spark does not allow two !='s in the same filter. Need to look at how filter is defined in Spark source code.
Now for your code to work, you can use this to do the filter
df.filter(col("item").notEqual("") && col("group").notEqual("-1"))
or use two filters in same statement
df.filter($"item" !== "").filter($"group" !== "-1").select(....)
This link here can help with different spark methods.