Is there a way to prevent Appian from sorting an integer array when it is autosa

Is there a way to prevent Appian from sorting an integer array when it is autosaving. Basically this happens in a multiple checkbox field. the choiceValues are 1 thru 12 and I am saving that to a local list array. I want to get the value of the last item that is checked in this checkbox field. The problem arises when there are many options selected randomly and then this saveInto sorts the values that are getting saved into this local variable and so the last value that is checked gets sorted and pushed to somewhere else in the array. The best I could do was to get the last item that is either checked or unchecked but I could not get the one that got checked before I unchecked something. This is the code below:
load(
local!lastValue,
local!tempValues:{},
local!compareValues:{},
local!multipleChoices:{},

with(
....formlayout and all that stuff .......

a!checkboxField(
label:"checkbox",
choiceLabels:index(local!display, "VALUE", {}]),
chioiceValues:...

OriginalPostID-144185

OriginalPostID-144185

  Discussion posts and replies are publicly visible

  • ... index(local!display, "ID", {}),
    value: local!multipleChoices,
    saveInto:{
    local!multipleChoices,

    if( rule!APN_isEmpty(local!multipleChoices), { a!save(local!lastValue, null)},
    {
    a!save(local!tempValues, local!multipleChoices[wherecontains(difference(tointeger(local!multipleChoices), tointeger(local!compareValues)), tointeger(local!multipleChoices)) ] ),

    if(length(local!tempValues) > 0, {
    a!save(local!lastValue, {local!tempValues[length(local!tempValues)]})
    }, {
    a!save(local!lastValue, difference(tointeger(local!compareValues), tointeger(local!multipleNotices)))
    }),

    a!save(local!compareValues, local!multipleChoices)
    }


    )
  • 0
    Certified Lead Developer
    It looks like you're on the right path with having an intermediary save (local!multipleChoices). After that you need to null check it (which you do). Now you just see if an item was added or removed by checking the length of local!multipleChoices and local!compareValues. The thing I would change is save your lastValue as an array of lasts, with the final value in the array being your last selected value.

    If local!multipleChoices is longer, that means you added an element, and so you'll find that element by doing difference(local!multipleChoices, local!compareValues). Simply append that value to your lasts array.

    if local!compareValues is longer, then you removed an element, so you'll need to also remove an element from your lasts array. To do that use the following: remove(local!lasts, wherecontains(difference(local!compareValues, local!multipleChoices), local!lasts))

    You may need to add some null checks for edge cases, but that should be your general strategy.