Text Function - insert() behavior

Certified Lead Developer

I have encountered a weird behavior related to insert() function. My use case is I am trying to insert 3 new values at the top of the list. 

E.g. Initial list is {"W","X","Y","Z"} and I try the insert command like insert({"W","X","Y","Z"},{"A","B","C"},{1,2,3})

But this command doesn't yield the expected result and yields output as {"A", "W", "B", "X", "C", "Y", "Z"}

 

Again I tried like this : insert({"W","X","Y","Z"},{"A","B","C"},{1,1,1}) and output is as expected : {"A", "B", "C", "W", "X", "Y", "Z"}

 

Can someone help me understand why {1,1,1} worked but {1,2,3} didn't?

 

Thanks in advance!

  Discussion posts and replies are publicly visible

  • Hi,

    From my understanding I think it is as expected (doc docs.appian.com/.../fnc_array_insert.html )

    the index value is determining where will you locate the data. So {1,1,1} is meaning all the three in the first position ("A", "B", "C") before "W"), When you give the other parameter {1,2,3} would be than A goes on the first position (before "W"), B goes on the second (where "X" was) and C goes to the 3rd (before "Y").

    Best regards,
    Manuel HTG
  • Hi, As per my knowledge insert function behavior as like that. Example insert({10, 20, 30, 40}, 100, {1, 2}) gives {100; 10; 100; 20; 30; 40} means first it would insert value at first postion result is {100,10,20,30,40} then later it still consider the initial input to insert the index of 2 then it becomes {100,10,100,20,30,40}. Because as we were doing insert not replace the values at positions.

    Hope it clears you.

    Regards,
    Vijay
  • Hi Harsha,

    In the link provided you can find the examples so that you will get to know the actual behaviour of the insert () function.
    docs.appian.com/.../fnc_array_insert.html

     An index value less than 1 appends the value to the left-side of the array, and an indexvalue greater than the array length appends the value to the right-side of the array.

     Example: insert({10, 20, 30, 40}, {100, 200}, {1, 2}) returns 100, 10, 200, 20, 30, 40


    Thanks,
    ravalik

  • Think of the index parameter as the index relative to the original array.
    Given your example:
    "A" precedes "W" because that's position 1 of the original array.
    "B" follows "W" because that would have been the 2nd position of the original array.
    "C" follows "X" because that would have been the 3rd position of the original array.

    Also, The following would put all your values at the top of the list:
    insert({"W","X","Y","Z"},{"A","B","C"},1)