LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Execute BRX - Using property values

    Employee
    Posted 11-11-2013 06:22

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Hi!

    I've been trying to create an execute BRX with evalIf statement but cannot get it to work.

    I have a field called ReportingLevel in my input data for execute BRX node. Possible values in this field are 1 and 2.
    As a simplified (this emit statement is not what I'm trying to achieve but gives the idea) example I would like to have something like this in the BRX:
    I have an input node that read certain data set in then a filter and then an excel output. The filter contains the following
    evalIf("{{*ReportingLevel*}}"=="1",emit "Reporting level is 1" as FieldXYZ)
    evalIf("{{*ReportingLevel*}}"=="2",emit "Reporting level is 2" as FieldXYZ)
    emit *

    However this structure does not seem to work. Even if ReportingLevel value would be 1 or 2 (as string) an output is created but none of the evalIf statements gets true as value so no emit is done. I've also tried another alternative without using evalIf by using separate two filters and a bypass node instead with the value of {{*ReportingLevel*}} controlling the filter enabled status but that does not seem to work either.

    Should this be something that is can be done inside BRX as I'm out of ideas why it does not work? At least the evalIf statement works just fine in normal BRG graph using normal parameters.

    By the way, what does the UseProperties parameter in excute BRX node do? Didn't fully get the idea from the node documentation.

    Thanks in advance!


  • 2.  RE: Execute BRX - Using property values

    Employee
    Posted 11-11-2013 07:41

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    EvalIf doesn't support expressions. It only supports the boolean constants of "true" or "false".
    But, it's possible that you can achieve the desired results with this bit of code:

    rl="Reporting level is unknown"
    if "{{*ReportingLevel*}}"=="1" then rl="Reporting level is 1"
    if "{{*ReportingLevel*}}"=="2" then rl="Reporting level is 2"
    emit rl as FieldXYZ


  • 3.  RE: Execute BRX - Using property values

    Employee
    Posted 11-11-2013 09:04

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    I'm still wondering as the following does work in normal BRG graph:

    evalIf("{{^ReportingLevel^}}"=="1",emit "Level 1" as FieldXYZ)
    evalIf("{{^ReportingLevel^}}"=="2",emit "Level 2" as FieldXYZ)

    If ReportingLevel parameter is set to 1 then "Level 1" string is shown in output and if ReportingLevel is set to 2 then "Level 2" string is shown in output. So the structure seems to be valid?


  • 4.  RE: Execute BRX - Using property values

    Employee
    Posted 11-11-2013 09:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hey,

    So stony's previous comment is mostly correct.

    evalIf can work in other circumstances though which can be a little confusing and this is what you are seeing when running through BRE.
    Effectively, evalIf is only supported when provided with a constant "true", or "false", or the direct textual substitution of a node or graph (not runtime) Boolean parameter.
    The boolean parameter in turn must not be defined as "Other", referencing runtime parameters.
    In addition, the case you are seeing is the fact that evalIf will work (although this is not documented or supported) when performing simple equality of the value of a textually substituted graph or node (not runtime) parameter. No other operations like brainscript functions will work within the context of the first parameter of the evalIf.

    This means that if on a given node you have a string parameter "StringParam", set to "p", and a boolean parameter "BooleanParam" set to false, then the following will work:

    #b1 will evaluate to false
    b1 = evalIf("{{^StringParam^}}" == "a", true, false)
     
    #b2 will evaluate to true
    b2 = evalIf("{{^StringParam^}}" == "b", true, false)
     
    #b3 will evaluate to false
    b3 = evalIf({{^BooleanParam^}}, true, false)
    What will not work is the substitution of any runtime parameters, or use of any BRAINscript functions etc.

    Assuming this is the information you need about the evalIf function then you can stop reading now.
    If you�re confused about this or why it�s this way, I�ve explained the mechanism to help understand why this is below....

    ----------------------------------------------------------------------------------------------------------------------------------------

    Evaluation of evalIf

    The rules for evalIf state that the first parameter must be a constant "true" or "false".
    However, what this really means is that at the time the BRAINscript is compiled, the first argument must be a "true" or "false".
    BRAINscript is compiled to an intermediary language when a BRX is generated.

    However, runtime parameters are not evaluated when generating the BRX - since these are to be provided when executing the BRX.
    Therefore, you cannot use a runtime parameter as the condition argument to evalIf as it will not evaluate to �true� or �false� when compiling the BRAINscript to generate the BRX.

    Textual substitution of non-runtime parameters occurs prior to compiling the BRX.
    Therefore, you can use substitution of a Boolean parameter into the condition argument of evalIf as it will evaluate to �true� or �false� when compiling the BRAINscript.

    The evalIf is actually not compiled into the intermediary language, rather the value of the condition is evaluated, and then either the consequent or the alternative is compiled depending on the condition.
    When trying to compile the evalIf, BRE will also try to perform any direct == comparators on constant arguments to obtain the value of the condition prior to determining whether it should compile the consequent or alternative.

    Therefore, using direct textual substitution of a graph or node parameter, in conjunction with the == notation you have used will work as the textual substitution occurs prior to compilation and the == evaluation is performed in the context of evalIf prior to the compilation.

    Attempting to use any BRAINscript expressions within the context of the condition of an evalIf will not work as these also need to be compiled, therefore they will not evaluate to true or false when the evalIf is being compiled.

    A bit complicated and long winded, but that's sort of the rundown on evalIf.

    Tim.


  • 5.  RE: Execute BRX - Using property values

    Employee
    Posted 11-12-2013 02:10

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    Ok thanks for the detailed explanation!

    What I'm really trying to achieve is to have a BRX that loads data from my project and applies a filter to it and then outputs a final report. Filter in BRX is for filtering the data based on an organizational unit and the BRX is used to loop the reporting process for each organizational unit. Due to I have many reporting level scenarios (all data to same report, one report for each organziational unit etc.) my idea was to have this filter/filters for which I would control the field on which the where clause is applied by a property passed to the BRX.

    I wonder if there actually still is some way to do this within a single BRX or is the only way to have multiple execute BRX nodes in my original project and to control their enabled/disabled status by the ReportingLevel parameter I have set up?


  • 6.  RE: Execute BRX - Using property values

    Employee
    Posted 11-12-2013 02:51

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Can't you use the syntax stony recommended previously - i.e.:

    rl="Reporting level is unknown"
    if "{{*ReportingLevel*}}"=="1" then rl="Reporting level is 1"
    if "{{*ReportingLevel*}}"=="2" then rl="Reporting level is 2"
    emit rl as FieldXYZ


    or something simliar, like:

    rl = null
    if "{{*ReportingLevel*}}"=="1" then rl="Reporting level is 1"
    if "{{*ReportingLevel*}}"=="2" then rl="Reporting level is 2"
    emit rl as FieldXYZ
    where rl != null


  • 7.  RE: Execute BRX - Using property values

    Employee
    Posted 11-12-2013 03:46

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    In my actual scenario I would need to control a where clause.

    Like:
    "{{*ReportingLevel*}}"=="1" -> Skip the filter altogether (=one report from whole data)
    "{{*ReportingLevel*}}"=="Company" -> filter the data where company matches a BRX property value like: where 'Company code'=="{{*ReportingUnit*}}"
    "{{*ReportingLevel*}}"=="Sales Organization" -> filter the data where sales organization matches a BRX property value like: where 'Sales organization'=="{{*ReportingUnit*}}"


    So I think I would have needed an evalif for this or then a bypass node and own filter for each reporting scenario with the filter's enabled/disabled status controlled by the ReportingLevel porperty. At least cannot think of an alternative solution by doing this in a single BRX with the new information I got. Having multiple BRX nodes in the original project has the downside of having to make changes to all of them when I make additions to the list of reported analyses.


  • 8.  RE: Execute BRX - Using property values

    Employee
    Posted 11-12-2013 03:56

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Ok..
    Maybe I'm not understanding the problem correctly, but couldn't you do all this by just using a filter node like the following:

    whereClause = false
    
    
    if ("{{*ReportingLevel*}}" == "Company") then
    {
        whereClause = 'Comany code' == "{{*ReportingUnit*}}"
    }
    else if ("{{*ReportingLevel*}}" == "Sales Organization") then {
        whereClause = 'Sales organization' = "{{*ReportingUnit*}}"
    }
    else if ("{{*ReportingLevel*}}" == "1" then {
        whereClause = true
    }
    #more clauses here?
    
    
    
    
    emit *
    emit "Reporting Level is {{*ReportingLevel*}}" as FieldXYZ
    where whereClause