Skip to main content

Hello there,

 

is it intended behavior/am I doing something wrong, that even with the type attribute for an input-box set to number, the variable will still be considered a string on javascript side once set to a value via the input box?

This of course results in the + operator behaving differently when performing calculations with javascript (see the example in the picture). While obvious in this case, as other operators will dynamically cast to int or float just fine and the default values work as intended before being changed by the variable input, it took more time than I'm willing to admit for me to understand, that this was the reason my annotation lines would sometimes not show up for my histogram.

 

Here the Yaml-code for the example:

metadata:

  key: variable-input-test

  template: false

  name: Variable Input test

  allowAdvancedFilters: true

variables:

  - id: Value1

    name: Value1

    defaultValue: 1

    type: NUMBER

  - id: Value2

    name: Value2

    defaultValue: 1

    type: NUMBER

layout:

  rows:

    - id: MainRow

      growHeight: true

      columns:

        - id: InputColumn

          layout:

            rows:

              - id: Value1InputRow

                columns:

                  - id: Value1InputColumn

                    componentId: Value1InputBox

                    size: "1"

                    order: 0

                order: 100

              - id: Value2InputRow

                columns:

                  - id: Value2InputColumn

                    componentId: Value2InputBox

                    size: "1"

                    order: 0

                order: 200

          size: "1"

          order: 50

        - id: MainContentColumn

          componentId: text-box-ba2824cd-d084-41b1-9c4f-64ebf080ed4d

          size: "5"

          type: default

          order: 100

      order: 100

components:

  - id: Value1InputBox

    type: input-box

    settings:

      name: Value1

      placeholderText: ${Value1}

      type: number

      onChange:

        update:

          variables:

            - name: Value1

  - id: Value2InputBox

    type: input-box

    settings:

      name: Value2

      type: number

      placeholderText: ${Value2}

      onChange:

        update:

          variables:

            - name: Value2

  - id: text-box-ba2824cd-d084-41b1-9c4f-64ebf080ed4d

    type: text-box

    settings:

      title: ""

      content: The "Math" of string addition says that ${Value1} + ${Value2} =

        ${Value1 + Value2}. The type of Value1 is ${typeof(Value1)}, the type of

        Value2 is ${typeof(Value2)}.

 

Kind regards,

Joshua

 

image.png

I believe that the type is only for the input by the user, all variables in Celonis are of type string and hence will still be considered a string  on javascript side. As you are already using functions the same should help you with the desired calculations.


Well, the default values are passed "correctly" as a number, hence why it may work at first but break once the variable input is used.

And yeah, it can be fixed using function to cast the type or the "-" operator will work fine in general as well, it was just not how i expected it to behave.

On that note: does the the type attribute for variables do anything?

Both the documentation under https://docs.celonis.com/en/views-variables.html as well as the code snippet have them.image.png


Reply