Choose value from multiple ranges based on user variable input

not very knowledgeable in KM so…

I have a script that asks a user’s input for a number (saves it in variable X)
I would like the script to use this number and translate it to another variable Y (number) based on some range table.
if Variable X from 0 to 10 than the output will be variableY = 120
if Variable X from 11 to 20 than the output will be variableY =100
if Variable X from 21 to 30 … variableY = 90
and so on. about 10 ranges like that.

I dont want to build a lot of IF statements. whats the optimum way ?

thanks

We can use Regex with a lookup table that should work well.

Please test this macro and let us know if it works for you.
You will need to edit the first Action in magenta to enter your data.
And then edit the Prompt Action to set the allowed values of X max.

2017-07-13 20:39 CT VER 2.1.1
• New version with different algorithm.
• Prior version did not work properly.

###Example Results

####Normal Results

####IF Error

###MACRO:   Set Variable Y Based on Range of Variable X @Extension

~~~ VER: 2.1.1    2017-07-13 ~~~

####DOWNLOAD:
Set Variable Y Based on Range of Variable X @Extension.kmmacros (9.8 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


###Use Case


###ReleaseNotes

Author.@JMichaelTX

NOTICE: This macro/script is just an Example

  • It is provided only for educational purposes, and may not be suitable for any specific purpose.
  • It has had very limited testing.
  • You need to test further before using in a production environment.
  • It does not have extensive error checking/handling.
  • It may not be complete. It is provided as an example to show you one approach to solving a problem.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
      .
  • Assign a Trigger to this maro.
  • Move this macro to a Macro Group that is only Active when you need this Macro.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    • ALL Actions that are shown in the magenta color

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge it will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

@dadarara, I made a couple of updates to my macro.
I just wanted to make sure you have the latest, which is Ver 2.1.1.

Hi
Thanks a million.
now to the issues :slight_smile:

As I have mentioned I am not very knowledgeable in KM.
so I have imported the downloaded makro. when I run it , it works.

but I have my own script with the user entry with additional parameters.

so how do I incorporate your macro inside my own macro ?
in my case, I dont what the Qty variable at all. I want it be calculated based on the TRIGGER.
so my X is the TRIGGER and the Y is Qty, to be later used down bellow in the macro.

thank you and sorry for my ignorance

Hi

Well, I managed to do it by adding my variables in your “user input” screen and by execute a macro within a macro (from my own). apparently the variables are public and my macro got them as well.

is this the optimum solution? is there a better one ?

Easy enough.
In my Macro REPLACE:

  • “SVY__X” with “Trigger”
  • “SVY__Y” with “Qty”
  • My Prompt User Action with your Prompt User Action