Robotic Process Automation (RPA)

Robotic Process Automation (RPA)

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  Calculate Mathematical Expression

    Posted 05/10/21 10:54 AM
    I am trying to get the absolute value of a number (dynamic) and to do that I am using the Calculate Mathematical Expression command, but I can't manage to make it work when using variables in the expression. It does work if I manually insert the values inside the expression, but it's useless that way. Here is what I am trying to do:
    defVar --name number --type Numeric
    defVar --name outputValue --type Numeric
    setVar --name "${number}" --value "1.2"
    evaluate --expression "Math.Abs(${number})" outputValue=value
    logMessage --message "${outputValue}" --type "Info"​

    The error I get:
    DynamicExpresso.NoApplicableMethodException: No applicable method 'Abs' exists in type 'Math' (at index 5).
       at DynamicExpresso.Parsing.Parser.ParseMethodInvocation(Type type, Expression instance, Int32 errorPos, String methodName)
       at DynamicExpresso.Parsing.Parser.ParseMemberAccess(Type type, Expression instance)
       at DynamicExpresso.Parsing.Parser.ParseIdentifier()
       at DynamicExpresso.Parsing.Parser.ParsePrimary()
       at DynamicExpresso.Parsing.Parser.ParseUnary()
       at DynamicExpresso.Parsing.Parser.ParseMultiplicative()
       at DynamicExpresso.Parsing.Parser.ParseAdditive()
       at DynamicExpresso.Parsing.Parser.ParseTypeTesting()
       at DynamicExpresso.Parsing.Parser.ParseComparison()
       at DynamicExpresso.Parsing.Parser.ParseLogicalAnd()
       at DynamicExpresso.Parsing.Parser.ParseLogicalOr()
       at DynamicExpresso.Parsing.Parser.ParseConditional()
       at DynamicExpresso.Parsing.Parser.ParseAssignement()
       at DynamicExpresso.Parsing.Parser.ParseExpressionSegment(Type returnType)
       at DynamicExpresso.Parsing.Parser.Parse()
       at DynamicExpresso.Interpreter.ParseAsLambda(String expressionText, Type expressionType, Parameter[] parameters)
       at WDG.Automation.Base.EvaluateCommand.Execute(AutomationContext context)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at WDG.Automation.Language.ErrorHandler.m0nvU46Nja(Exception  )
       at WDG.Automation.Language.ErrorHandler.HandleExecutionExceptionIfNeeded(Exception exception, IAutomationCommand command)
       at WDG.Automation.Language.CommandInterpreter.<Run>d__12.vQ7xHXNECMOJPEvfGI5(Object , Object , Object )
       at WDG.Automation.Language.CommandInterpreter.<Run>d__12.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at WDG.Automation.Language.ScriptInterpreter.<RunCore>d__17.MoveNext()​


    Am I doing something wrong or is this a bug?



    ------------------------------
    Vinicius Marques
    ------------------------------


  • 2.  RE: Calculate Mathematical Expression

    Posted 05/11/21 05:53 AM
    Hi vinicius,

    I don't think RPA has Abs built in.  But you can caculate it.  See https://en.wikipedia.org/wiki/Absolute_value

    ------------------------------
    NIGEL CROWTHER
    ------------------------------



  • 3.  RE: Calculate Mathematical Expression

    Posted 05/11/21 06:03 AM
    Oh I see the problem.  It works if you put in an actual number, but not a variable.  I think that is a bug!

    ------------------------------
    NIGEL CROWTHER
    ------------------------------



  • 4.  RE: Calculate Mathematical Expression

    Posted 05/16/21 01:39 PM

    Here's a similar issue that i resolved with the code below.

    Math.Pow(Convert.ToDouble(${vInteger}),2)

    -The reported problem happens because .NET does not understand IBM RPA's Numeric type (i.e. the type vInteger is declared as). So when the underlying engine behind evaluate command tries to evaluate Math.Pow(${vInteger},2), it can't find any Pow method accepting a NumericVariant type. The same would happen for any method where you pass a variable as a parameter. No .NET method will understand any IBM RPA's type, so a explicit cast is needed. Thankfully, the engine understands conversion at runtime, so whenever you run into this type of problem, try using one of those methods from .NET's Convert class.



    ------------------------------
    ZACHARY SILVERSTEIN
    ------------------------------



  • 5.  RE: Calculate Mathematical Expression

    Posted 05/17/21 03:42 AM
    Thanks Zach

    ------------------------------
    NIGEL CROWTHER
    ------------------------------



  • 6.  RE: Calculate Mathematical Expression

    Posted 05/17/21 08:18 AM
    Thanks!

    ------------------------------
    Vinicius Marques
    ------------------------------