Expression rule

Certified Associate Developer

How to write a rule which takes two input a char and an integer,
ruleInput: (A,2)
Output: (A1;A2) 

anyone can give me the answer 

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    The requirement is not clear. Share more details.

    You can create a rule input of Text type and then pass comma-separated data in that.

  • 0
    Certified Senior Developer

    How are you passing this value?

    Also as Yogi Patel mentioned create a Rule input of text type and try this.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    a!localVariables(
    local!value: ri!ruleInput,
    local!integer: cleanwith(local!value, "1234567890"),
    local!alphabet: stripwith(local!value, "123456789(),"),
    local!listOfInt: enumerate(tointeger(local!integer)) + 1,
    a!forEach(
    items: local!listOfInt,
    expression: concat(local!alphabet, fv!item)
    )
    )
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I would ask you to please share what you have tried and what exactly is the requirement. 

  • Hi, based on your input and output I am guessing you are trying to concatenate two inputs n number of times. if so, below snippet could be helpful

    for

    Fullscreen
    1
    2
    3
    4
    a!forEach(
    items: enumerate(ri!integer)+1,
    expression: concat(ri!text,fv!index)
    )
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 0
    Certified Lead Developer
    in reply to Yogi Patel
    The requirement is not clear.

    I like defaulting to the laziest approach possible when the requirements aren't actually spelled out.  For instance, the result here is just a rule that returns "(A1;A2)", without specifying how the rule input (if any) is related to that (and my brain is too fried to try guessing).

    So here's my initial rule suggestion:

    Fullscreen
    1
    "(A1;A2)"
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Straightforwardness: 10/10.  Flexibility for different rule inputs: ??/10.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Less lazy reply:

    let's pretend the rule input is actually 2 inputs, a character and a "times repeated".  I don't feel like writing a parser to accept a comma-separated value when that may have just been OP overly abbreviating what their input is going to be.

    Fullscreen
    1
    2
    3
    4
    a!forEach(
    enumerate(ri!repeats),
    ri!character & fv!index
    )
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    For "A" and 2, that gives us basically their prescribed output:

    For "C" and "11", it performs more of the same: