Group typo3 condition - typo3

I need such a condition in ts:
([treeLevel = 0] && [globalVar = GP:R > 0]) || [PIDinRootline = {$pages.2018}]
I wanna show block if page has treelevel=0 and the get var R > 0, or if page id = $pages.2018
It looks like the similar code in php:
if(($treeLevel == 0 && $r > 0) || (pid == number))
The all expression in first brackets should be right, or in second.
Is it exist the method to group it like the previous record or I can only use userfunc?

There is no grouping in TS conditions, but if you need this particular condition from your post I think it is not needed because brackets around && are useless in this case.
(p && q) || r
is exactly the same as
p && q || r
Did you tested it?

Related

Drools rule with not condition with multiple condition causing error

When i use below condition with 'not' I am getting an error.
not(Obj1(value == 0) && Obj2(value <= 3))
However if i replace above condition as below I am not getting any casting exception
Obj1(value != 0) or Obj2(value > 3)
The rule looks like this:
rule "test_6"
salience 10
when
not(Obj1(value == 0) && Obj2(value <= 3))
then
.....
end
And this is the error I'm getting:
throwing error Error Message: org.drools.core.rule.GroupElement cannot be cast to org.drools.core.rule.Pattern
The && and || operators can only be used inside a single pattern. For example: Obj1( value > 3 && value < 10 || value == 0). According to the documentation, to separate Patterns, you have to use the and and or operators.
So, in your case, your rule should be:
rule "test_6"
salience 10
when
not(Obj1(value == 0) and Obj2(value <= 3))
then
.....
end
Note that it was not failing when you were using or because that was the right operator to use instead of ||.
Hope it helps,

Date range in query Dynamics AX

I would like to build query Range, where
ActiveTo < today || ActiveFrom > today.
Is it possible, I tried something like that but it's not working.
qbdsDimAttrValue = ds.addDataSource(tableNum(DimensionAttributeValue));
qbrMainAccountActiveFrom = qbdsDimAttrValue.addRange(fieldnum(DimensionAttributeValue,ActiveFrom));
qbrMainAccountActiveFrom.value(strFmt('(((%1.%2 != 0) || (%1.%3 != 0)) && ((%1.%2 > %4) || (%1.%3 < %4)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue,ActiveFrom),
fieldStr(DimensionAttributeValue,ActiveTo),
today(),
));
I write 0, because in table DimensionAttributeValue if field ActiveFrom, ActiveTo is null it has value 0, not dateNull(), dateMax()
Date values used in such queries must be in the dd\MM\yyyy format - you can use function date2StrXpp() for this purpose.
Try using the following range:
qbrMainAccountActiveFrom.value(
strFmt('((%1.%2 > %4) || ((%1.%3 < %4) && (%1.%3 != %5)))',
qbdsDimAttrValue.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
date2StrXpp(systemDateGet()),
date2StrXpp(dateNull())
));
If you check Global::dateNull() you will see that it returns '01\01\1900', also you can see that database doesn't store 0 in these fields:
Yo can find more details here
So you can simplify your extended range as follows
qbrMainAccountActiveFrom.value(strFmt('((%1.%2 > %4) || (%1.%3 < %4))',
qbds.name(),
fieldStr(DimensionAttributeValue, ActiveFrom),
fieldStr(DimensionAttributeValue, ActiveTo),
today()
));

Why !(0 || 1 || 0) is 0?

I am trying to understand Boolean logic and operators.
I found this example but can't understand why this expression will evaluate to the one shown below.
Say, a = 0, b = 1, c = 0
Expression Will Evaluate to
val1 = !(a || b || c); !(0 || 1 || 0) = !(1) = 0
As I see it, val1 is not a or not b or not c, so why it evaluates to not 1 ?
Not(a or b or c) evaluates the or operations first, so it's not the same as (not a) or (not b) or (not c).
Indeed, it's the same as (not a) AND (not b) AND (not c).
Either operand to an OR being true will give a true result, and then the NOT flips that to a false result for the expression as a whole.
As with integer or real number arithmetic, order of operation can greatly alter the result.
.... val1 is not a or not b or not c ...
No, this is incorrect. The 0 || 1 || 0 inside the parenthesis is evaluated first. The example has it right.
Let's say val1 = 1
1 = !(0 || 1 || 0)
1 = !(1) - because it is the only value that is equal to val1
1 = 0 - then it negates it afterwards
Let's go step-by-step.
val1 = !(0 || 1 || 0);
Firstly, 0 || 1 will evaluate to 1, because || means 'true if at least one of them is true, otherwise false', and 1 = true, 0 = false.
So now it is
val1 = !(1 || 0); Here 1 || 0 will again evaluate to 1, because at least one of them is 1. Now we've got val1 = !(1);. ! means the opposite of the input, so !(1) = 0.
As I see it, val1 is not a or not b or not c, so why it evaluates to not 1 ?
Because what you say would be written as val1 = !0 || !1 || !0. Its quite different, because it doesn't have parenthesis. Parenthesis means 'evaluate everything in the parenthesis first'.

How do I add a condition to an existing conditional expression?

I had a programmer write a Perl script for my site.
One of the functions is to update price/stock when a certain condition is met.
# update when price/stock conditions met
if ( ($force_price_updates == 1) ||
($data->{'price'} <= $product_price && $data->{'quantity'} > 0) ||
($product_quantity == 0 && $data->{'quantity'} > 0) ) {
What the above is not doing is not updating the price if the new price is higher. It updates the stock value, but if the new stock comes at a higher price, I lose out. Stock gets updated and but the price is not.
The script goes through a number of feeds and if the same product is found in any of the feeds, the script should amend price/stock change according to the rule above.
I can't find the programmer and my Perl knowledge is limited. I understand what the code is doing, but don't know what it should do if the price is higher and stock is greater than zero.
You can add the extra condition you're looking for to that statement.
The condition you're looking to match is:
$data->{'price'} > $product_price && $product_quantity > 0
So the final version would look like this:
if (($force_price_updates == 1) || ($data->{'price'} <= $product_price && $data->{'quantity'} > 0) || ($product_quantity == 0 && $data->{'quantity'} > 0) || ($data->{'price'} > $product_price && $product_quantity > 0)) {

Multiple statements in where clause

I have this strange problem. I have a simple search requirements where a user can search a given entitiy (Say customer) based on several search criterias. User may choose to use a criteria or not. The search conditions need to 'AND' all the criteria. So I write code like this (which works)
IQueryable _customer;
_customer = from c in DS.properties
where
(txtCustomerName.Text.Length == 0 || c.name == txtCustomerName.Text)
&& (txtpropcust1.Text.Length == 0 || c.customfield1 == txtpropcust1.Text)
&& (txtpropcust2.Text.Length == 0 || c.customfield2 == txtpropcust2.Text)
&& (txtpropcust3.Text.Length == 0 || c.customfield3 == txtpropcust3.Text)
&& (txtpropcust4.Text.Length == 0 || c.customfield4 == txtpropcust4.Text)
&& (txtpropcust13.Text.Length == 0 || c.customfield13 == txtpropcust13.Text)
select c;
GridView1.DataContext = _customer;
The problem is that if I have 14 where clauses, the EF throws an error- 13 works - 14 does not.
I am using EF+WCF data service in a WPF application. Is there a setting somewhere which limits the number of where clauses?
Thanks
To simplify the resulting query, you could use:
var customers = DS.properties;
if (txtCustomerName.Text.Length > 0)
customers = customers.Where(x => x.name == txtCustomerName.Text);
if (txtpropcust1.Text.Length > 0)
customers = customers.Where(x => x.customfield1 == txtpropcust1.Text);
// etc
_customer = customers;
GridView1.DataContext = _customer;
Note that this will only add SQL where clauses when there's a need for it.