0

Multiple choice picks in order?

Hi all.

Anyone knows how to extract a list of items from a MC list in the exact order in which those items are selected?

I.E. Let's say I have a mc field where

1. apple

2. pear

3. cherry

A concat() would extract Apple, Pear, Cherry regardelss of the order in which they are selected. Is there a way to concat those choices in the order they're selected in?

Thanks a lot!

Gianluca

17 replies

null
    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Gianluca ... Interesting use case..   I see that chosen('mc field name') does the same..   If the order of selection is important, I suppose you could build a hidden / composite table .. and then populate that table in an After Update trigger.    The user would still use the multiple choice field.. but you would populate the hidden composite table in the order selected... Just a thought.. 

    • Birger_H
    • 4 yrs ago
    • Reported - view

    Every Choice has an ID. yYou can get the selected IDs with the function numbert('Multiple Choive Field').

    Birger

    • gsechi_centrostudimlit
    • 4 yrs ago
    • Reported - view

    Thanks for your reply. Actually either chosen() and number() extract the items keeping their original order. By choosing 1-3-2 my chosen() would give 1-2-3. I need to tell NX to give me 1-3-2 (or those in any other order).

    • Mconneen
    • 4 yrs ago
    • Reported - view

    Birger, 

    That is interesting... however, this use case is... tell me the ORDER in which a multiple choice box was populated.  So in the following I want choosen('Multiple Choice')  .. or text('Multiple Choice') to return ... "Choice C, Choice A" ... 

    firstChoice

    secondChoice

    What is also interesting is that number('Multiple Choice') returns a sumation of choices .. in the above case 4+1 = 5.. Hmmm

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, it should be numbers() not number()

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Sean... Ahh.. ANOTHER Easter Egg... LOVE IT..   As expected.. the array is still does not satisfy the request.. as it is not in order clicked.. it is in ordinal position...   Thanks!

    • Mconneen
    • 4 yrs ago
    • Reported - view

    numbers

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, yeah, this one truly is an Easter egg. I searched for it in the Reference page and didn’t find it. First time I heard of it was here...

     

    https://ninoxdb.de/en/forum/technical-help-5ab8fe445fe2b42b7dd39ee7/how-can-i-add-two-arrays-5c88bfff3a267b36b13dd50d

    • gsechi_centrostudimlit
    • 4 yrs ago
    • Reported - view

    @Mconneen. It returns 5 in this release, somehow in previous releases you could get numbers as well as letters, depending on the available choices I suppose. It seems that multiple choice fields act like extended versions of single choice fields, rather than serving as a item-as-chosen list. Implication being that I should stop shouting out "please give me that order!" and that any help with this would be more than a (virtual) beer worth this time....

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, Have you worked out the logic yet? ;)

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Sean... Other than learning the number.. numbers .. chosen.. functions..  I have not really put much more thought into it.   I suspect a hidden choice table could be created .. and then an after update trigger could figure out which item was added / removed .. and manipulate the table..   or you could use a single choice box.. with and add/remove button and build the choice table... or..... pull the choices out to checkboxes / switches and have an after update trigger call a common function that adds / remove to the choice table... then use the concatenate to display them in the order checked..... or ... just build an inner choice table and let them use the out of the box functionality.. or..... ;)

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, Hmmm, I guess I'm not seeing the single Choice solution unless you have one Choice field for every Multiple Choice option. I tried using a separate table to store the Multiple Choice options and that seemed like a lot of unnecessary work. This is what I came up with...

     

    let curChosen := OPChosen;
    let newChosen := chosen(MC);
    let myContains := true;
    let mcCount := count(numbers(MC));
    let x := 0;
    while myContains and x < mcCount do 
    if contains(curChosen, item(newChosen, x)) then
    x := x + 1
    else
    myContains := false
    end
    end
    ;
    if OPChosen > "" then
    OPChosen := curChosen + "," + item(newChosen, x)
    else
    OPChosen := item(newChosen, x)
    end

     

    OPChosen is just a Text field that I store the result in. I use a Formula field to display it with more formatting options. This does not test for removed items so that will break it.

    • Sean
    • 4 yrs ago
    • Reported - view

    Ooops, forgot to mention that the code goes in the "Trigger after update" for the Multiple Choice field.

    • Sean
    • 4 yrs ago
    • Reported - view

    @gsechi, I don't know if you are interested, but here is a solution that works for selection and deselection. It requires a Text field to store the ordered Multiple Choice selection/deselection and the result can be displayed in a Formula field. Here is a screenshot...

     

    Screen Shot 2019-04-14 at 8.49.39 PM

     

    The OPChosen field can be hidden or be used instead of the Formula field. I'm not completely happy with the code, but it works. The following code goes in "Trigger after update" for the Multiple Choice field...

     

    let curChosenText := OPChosen;
    let curChosenArray := split(replace(OPChosen, ", ", ","), ",");
    let curCount := count(curChosenArray);
    let newChosenText := replace(concat(chosen(MC)), ", ", ",");
    let newChosenArray := chosen(MC);
    let newCount := count(newChosenArray);
    let myContains := true;
    let x := 0;
    if newCount > curCount then
    while myContains and x < newCount do 
    if contains(curChosenText, item(newChosenArray, x)) then
    x := x + 1
    else
    myContains := false
    end
    end
    ;
    if OPChosen > "" then
    OPChosen := curChosenText + "," + item(newChosenArray, x)
    else
    OPChosen := item(newChosenArray, x)
    end
    else
    while myContains and x < curCount do 
    if contains(newChosenText, item(curChosenArray, x)) then
    x := x + 1
    else
    myContains := false
    end
    end
    ;
    var tmpArray := for idx from 0 to curCount do
    if idx != x then
    item(curChosenArray, idx)
    end
    end;
    OPChosen := replace(concat(tmpArray), ", ", ",")
    end

     

    The Formula field code...

     

    replace(OPChosen, ",", "
    ")

     

    The "," is replaced by alt+enter or option+return.

    • Sean
    • 4 yrs ago
    • Reported - view

    @Mconneen, The separate table approach would be pretty handy if someone wanted to timestamp the different picks.

    • gsechi_centrostudimlit
    • 4 yrs ago
    • Reported - view

    @Sean. Thanks. Not much time spent on this in the last couple of days, but I'll try your solution and I'll get back as soon as I can. Thank you for your time.

    Gianluca

    • Sean
    • 4 yrs ago
    • Reported - view

    For anyone that is interested this is a version that I'm a little happier with...

     

    "// Initialize variables";
    let curChosenText := OPChosen;
    let curChosenArray := split(OPChosen, "|");
    let curCount := count(curChosenArray);
    let newChosenText := replace(concat(chosen(MC)), ", ", "|");
    let newChosenArray := chosen(MC);
    let newCount := count(newChosenArray);
    let myContains := true;
    let x := 0;
    "//";
    "// Update OPChosen if an item is selected";
    if newCount > curCount then
    while myContains and x < newCount do 
    if contains(curChosenText, item(newChosenArray, x)) then
    x := x + 1
    else
    myContains := false
    end
    end
    ;
    if OPChosen > "" then
    OPChosen := curChosenText + "|" + item(newChosenArray, x)
    else
    OPChosen := item(newChosenArray, x)
    end;
    "//";
    "// Update OPChosen if an item is deselected"
    else
    while myContains and x < curCount do 
    if contains(newChosenText, item(curChosenArray, x)) then
    x := x + 1
    else
    myContains := false
    end
    end
    ;
    curChosenArray := unique(slice(curChosenArray, 0, x), slice(curChosenArray, x + 1, count(curChosenArray)));
    curChosenText := "";
    "//";
    "// Custom concatenating loop";
    for i in range(0, count(curChosenArray)) do
    curChosenText := curChosenText + item(curChosenArray, i) + "|"
    end;
    OPChosen := curChosenText
    end

     

    This is what I do when shippers take a long time to load the trailer. 😁

Content aside

  • 4 yrs agoLast active
  • 17Replies
  • 5208Views