Power Automate Expression for Multiply - azure-logic-apps

Issue : Unable to multiply in Power Automate.
Error Message :
Unable to process template language expressions in action 'Sales_with_Delta' inputs at line '0' and column '0': 'The template language function 'int' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.
Expression used for multiplication :
mul(int(outputs('Compose')),float(variables('delta')))
Flow Configuration
Question:
Can you please help with mul expression ?
I want to multiply 'Sales' with 'delta' inside 'Sales with Delta' variable
Please note
I cannot change the variables declared as 'Compose' or 'Object'

You need to be specific when you're referring to a property in an object, try this ...
mul(int(outputs('Compose')['Sales']),float(variables('delta')))
Worked for me ...
... you may just need to work through the .00001 decimal part of the result that you may not want there.

Related

Eiffel: setting a constant with reference to other class constant

How to set a constant refering to another class constant in Eiffel?
Something like that doesn't compile unfortunately
Default_log_level: like {MY_LOGGER}.log_level = {MY_LOGGER}.Log_level_info
Constant attributes cannot be defined using other constant attributes in the current version of Eiffel.
Constant attributes can only be made of a manifest constant, but a possible workaround could be to use frozen once functions:
frozen Default_log_level: INTEGER
once
Result := {MY_LOGGER}.Log_level_info
ensure
definition: Result = {MY_LOGGER}.Log_level_info
end
frozen means that it cannot be redefined in descendant classes (like constant attributes).
Unfortunately, the type of once functions cannot rely on anchored types, hence the use of INTEGER instead of like {MY_LOGGER}.log_level.
And finally, the drawback with this solution is that it cannot be used where constant attributes are expected (e.g. in inspect instructions).

Step Function For Array in Anylogic

How to use an step function for an array in Anylogic?
step function is applied to double values, but I want to applied on elements of an array at a specific time.
You can't... so this is a solution:
Instead of an array you should use a linkedHashMap where your key is the specific time and the element is the step value you want at that time. So you defined it as follow:
And you put the values like this:
stepsArray.put(3.0,2.3);
where 3.0 is the time in which the step will occur and 2.3 is the value the step will take. You have to put there all the values you need. You are the one who has to fill these values according to your needs.
Then you create an cyclic event that will evaluate if it's time to apply a step and you create a variable of type double that will be the one storing the value of the step.
So, the event:
double theTime=round(100*time())/100.0;//it's better to round up the time just in case
if(stepsArray.containsKey(theTime)){
variable=stepsArray.get(theTime);
}
note that I'm using a variable, not a dynamic variable.. they you can connect the variable to wherever your step is needed in the sd model.
This method is a bit complicated, but it's the most general for your completely ambiguous question.
Not sure Felipe's approach is the best one but maybe I misunderstand the question.
Have you tried using a "table function" object? Define it as below where the horizontal axis represents the time unit and the vertical your step function data:
Then, use a cyclic event that every relevant time unit (depends on your model) pulls the current required value from the table function:

Check if Json Array contains objects in Logic App

I am trying this out but I cant seem to get it to work.
In a Condition connector I'm doing this:
#contains(json(body('ParseCustomerDeltaXML')).newMembers[0], 'Member')
but i cant get it to work.
If it contains members it says true.
But if not i get an error:
InvalidTemplate. Unable to process template language expressions for action 'Condition' at line '1' and column '2706': 'The template language expression 'equals(json(body('ParseCustomerDeltaXML')).newMembers[0], null)' cannot be evaluated because array index '0' cannot be selected from empty array. Please see https://aka.ms/logicexpressions for usage details.'.
As indicated by the error message, the array you are trying to reference the first item of is empty. You want to make use of the safe dereference operator .?
Suppose newMembers is an empty array. Then newMembers[0] would fail, but newMembers?[0] would succeed (and return null).
In the specific scenario you are describing, you may need to use a nested condition as well (i.e. first check if newMembers is non-empty, and then check for membership).
To check for emptiness you can use the #empty() expression.
In my example I should check is element empty before fetching street data from element.
This works:
if(empty(body('Parse_JSON')?['results'][0]['addresses']), '', body('Parse_JSON')?['results'][0]['addresses'][0]['street'])
and this works too:
if(contains(['addresses'], ['addresses']?[0]), 'Do something', 'Or do this thing')
Hope that will help someone.

In XDocReport, how to handle null value?

Is there a way to handle null value for a field in XDocReport? or do I need to manipulate it on my own? example:
if (thisVar == null)
context.put("sampleText", "");
else
context.put("sampleText", thisVar);
or is there an option in docx quick parts?
I found this line in the error message of XDocReport. However I could not understand where to apply this, in the template or in the code.
Tip: If the failing expression is known to be legally refer to
something that's sometimes null or missing, either specify a default
value like myOptionalVar!myDefault, or use [#if
myOptionalVar??]when-present[#else]when-missing[/#if]. (These only
cover the last step of the expression; to cover the whole expression,
use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
In docx, append ?if_exists to the field name
«${tx.amount?if_exists}»
you may also append !
«${tx.amount!}»
Please refer to this link for those who uses freemarker. How to check if a variable exists in a FreeMarker template?

get fieldname of a data struct matlab

I have the following nested struct:
hole 1x200 struct, diam 1x12 struct, which has the following fields: pos, freq1, fre12
That is:
hole(1 to 200).diam(1 to 12).pos
.freq1
.freq2
From a value (freq1 and freq2), I would like to obtain the field name of the struct. So I will need to find the value that matches with freq1 and freq2 and show the fieldname.
I tried to use structfun in order to apply a function to each field.
[struct.field]=structfun(#(x) find(x.freq1==27.059783995484867 & freq2==76.468355874897000))
But I guess I am writing something wrong on the code.
Also I create an anonymous fuction but I have the following error:
'Error using structfun / Inputs to STRUCTFUN must be scalar
structures'
. How ever when I verified if an specific value of the struct is scalar, I have a positive answerd: isscalar(hole(130).diam(10))
I belive I more near the solution using this script:
myfun=#(yourarray,desiredvalue) yourarray==desiredvalue;
%//Apply function to each field of scalar structure, it SCALAR??
desiredfieldindex=myfun(structfun(#(x) x,hole),26.697046257785030)
desiredFieldName=fNames(desiredFieldIndex)
I don´t know if I am in the rigth path, or I should utilize the function find. ALso I that case I don´t know how to implement it.
Couple of things.
FLOATING POINT VALUES! Careful!! Never compare a floating point value as val==0.3! do abs(val-0.3)<10^-8 or something similar. Read more here.
You are using structfun wrong. The function needs 2 arguments, and you are just passing 1! However, structfun will apply a function to each field so you are not using it rigth either in that sense. Lets see an example
example:
a.hithere=5;
a.notthis=3;
fun=#(x)x==5;
[isfive]=structfun(fun,a)
isfive =
1
0
As you can see, it applies the function to each of them. If you try to change the function to fun=#(x)x.hithere==5 you will get an error! As the function is applied to each field, and x.hithere.hithere or x.notthis.hithere do not exist.
If you want to check both values, you will need to check them independently making two separated calls to structfun or avoiding structfun and just making a for loop.

Resources