NLog Conditional Variable Value - conditional-statements

In NLog, is there a way to have a variable with a conditional value? I've seen this: https://github.com/NLog/NLog/wiki/When-Layout-Renderer and tried the following:
<variable name="EnvironmentString" value="${when:when='${IsProd}' == 'true':Prod:else:Stage}"/>
but the value is just returned as a literal; the logic is not being processed.
Thanks,

1) Change the syntax to this:
${when:when='${var:IsProd}'=='true':inner=Prod:else=Stage}
Note:
:else= rather than :else:
:inner=
var:IsProd (assuming IsProd is another variable)
2) Move the whole conditional to the final Layout
<target ... layout="other stuff|${when:when='${var:IsProd}'=='true':inner=Prod:else=Stage}|other stuff" ... />
I've not managed to get conditionals working in variables. Perhaps someone else could say why.

This should work.
But it depends how the variable is used.
If you use:
${EnvironmentString}
Then it's evaluated when loading the configuration, and so you could use it for all parameters.
To evaluate it dynamically, use
${var:EnvironmentString}
But please note that ${var} only works if the parameter of the Target/Layout is of type Layout

Related

Access FlowVar dynamically in DataWeave

I'm trying to access a FlowVar name dynamically in DataWeave.
For example:
I have a flowVars named taxInfo123. This is a linked list and my applicant.ApplicantID = 123
In my dataweave, I want to access this dynamically. Something like the following:
"TaxInfo": flowVars.'taxInfo'+applicant.ApplicantID map ((taxIdentificationDetail , indexOfTaxIdentificationDetail) -> {
This obviously doesn't work, and I'm hoping this is possible and I just need the correct syntax.
If you need to dynamically create the variable name, you can use the flowVars[key] syntax instead of the flowVars.key syntax. In your scenario:
"TaxInfo": flowVars[('taxInfo' ++ (flowVars.applicant.ApplicantID as :string))]
I assumed applicant was also a flowVar but you could just as easily use payload.applicant.ApplicantID or whatever your situation calls for. I also assumed it was a number so I had to cast it as a string.
When you use this syntax you want to make sure you wrap the key expression in parenthesis so it is evaluated first and then the flowVar is resolved.
So to summarize:
If you know the variable name is 'taxInfo123' -
flowVars.taxInfo123 or flowVars[taxInfo123] are both valid
If you need to create the variable name dynamically -
flowVars[(expression)]
Hope that helps!
Forming the variable name needs append operator like ++. Please go through the MuleSoft documentation for Dataweave operators to get better understanding of how much flexiblity is possible in Dataweave.
https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators

String template to set the default value of PARAMETER

Is it possible, in ABAP, to evaluate string templates dynamically?
Normally, you will have some string template in code that will be checked by the compiler. (The variables in the curly brackets are checked by the compiler at compile time).
However, is it possible to have a string evaluated at runtime?
So, instead of:
data(val) = |System ID: { sy-sysid }|.
I would like the string to be interpolated to come from elsewhere, for example:
parameter: p_file type string lower case default '/mnt/{ sy-sysid }/file.txt'.
In this case, I would like to have the value of p_file to be evaluated at runtime to substitute the variable (sy-sysid) with the runtime value.
You could, of course, program your own substitution by finding all occurrences of variables with curly brackets with a regex expression, then evaluate the variable values with ASSIGN and substitute them back into the string, but I am looking for a built-in way to do this.
Sorry, this is maybe a stupid example, but hopefully you understand what I mean. (If not, please let me know in the comments and I will try and clarify).
The problem in your snippet is not with string template but with PARAMETER behavior. It does not allow dynamics in DEFAULT clause.
To achieve what you want you should use INITIALIZATION and set path value in runtime:
parameter: p_file type string lower case.
INITIALIZATION.
p_file = | /mnt/{ sy-sysid }/file.txt |.
Unfortunately, the example you gave, does not make any sense to me. ABAP String templates are evaluated at run-time and type-checked at compile-time.
In your example, it is always the run-time value of SY-SYSID that will be written to the variable.
I guess what you want to do is circumvent compile-time checks for expressions inside a string template.
Please try to give us your actual use case, so maybe we find an even better solution to your problem.
However, here is what I think could help you:
Personally, I do not recommend to write code like the one below, because it is extremely error-prone likely to mislead other programmers and because there is very likely a better solution.
Given that you know the name of a variable at run-time, try this:
".. say LV_VARNAME is a charlike variable that contains a
" variable name at runtime.
"NOTE that the variable LV_VARNAME must be visible in the scope of the
"following code.
FIELD-SYMBOLS: <my_var> TYPE any.
ASSIGN (lv_varname) TO <my_var>.
DATA(lv_str) = |The value is { <my_var> }|.

How to assign a variable in MVEL Template

I would like to assign variables in an mvel template.
Assuming that my template has only a property foo defined, I would like to do the following:
#{bar=foo}
#{bar.name}
Unfortunately this outputs me the toString() of foo and then the property name of bar. I would like to do the same but without printing anything with the assignation.
(just in case anyone lands here...)
According to this documentation, you can use #code blocks to execute statements without emitting output.
#code{bar=foo}
#{bar.name}

Is there an equivalent of isset or a null coalescing operator in SASS?

I want to set a variable only if it hasn't been set.
SO...
In _layout.scss:
$page-width: 1100px;
However, in my _module.scss file, I don't want to have a dependency on _layout.scss
I'd like to do something like this :
$page-width = $page-width ?? 960px;
// If $page-width exists, use it, otherwise set it to a default of 960px;
I'd like something that preferable works in SASS 3.2. I found a solution here, otherwise:
global-variable-exists is triggering errors in Sass
I believe you are looking for variable defaults, and SASS supports them. Variable defaults allow you to assign to variables if they aren't already assigned using ! at the end of the value.
In your case, you can use this in _layout.css:
$page-width: 1100px;
And then in _module.scss you can
$page-width: 960px !default;
This is roughly equivalent to saying assign $page-width to 960px unless $page-width is already defined.
Check out the docs on default variables.
Mohamad's answer is the best one for your particular code example, but it's worth mentioning that the Sass or operator can sometimes be used as a drop-in replacement for the ?? operator:
$my-property: $uncertain-variable or $backup-value;
I say 'sometimes', because it's only good if your $uncertain-variable has been defined.
This is more reliable than some languages—cough JavaScript—because as the Sass docs point out:
Some languages consider more values falsey than just false and null. Sass isn’t one of those languages! Empty strings, empty lists, and the number 0 are all truthy in Sass.
Whether you want to use or this way is a matter of personal preference I suppose. While it's very succinct, you could argue that an #if statement (or if() function) is more explicit.
Yes. As of version 3.1.2, there's an if function, that takes three arguments; the condition to check, and two values, one of which is returned, depending on the result:
if(condition, value-returned-if-true, value-returned-if-false);
This may useful when you don't want to set up defaults elsewhere in your code.

specifying a parameter instead of explicit value in process task

I have a process task:
I'm wondering whether it's possible to pass something like this into it:
$Package::targetLocation
Thank you for your guidance,.
You should be able to do this with the Expressions tab, create a new expression against the Arguments property and assign this to your user variable.