0

Converting a text string to a multiple choice field

Hello!

I've been having trouble figuring this out and I would love some help.

I have a work flow that involves a potential guest (school groups visiting our site) filling out a form that auto-populates into a table in Ninox to create a request that a member of my team can review/approve.  Most fields are working just fine with simple functions (ex: Date := 'Second Choice Date'; 'Time Start' := 'Second Choice Time'), but I am having trouble with converting age groups from a text field in the request section ('Request Ages') to a multiple choice field ('Grade Level(s)') in the approved section (both are in the same 'Booking' table).

I've been trying with replace and contains functions, but there doesn't seem to be a straight forward way to replace a text string with numbers unless you only need a single number. 

For reference, here are a couple of things that I've tried that haven't worked:

let x1 := replace('Request Ages', "2nd", "5");
let x2 := replace(x1, "4th", "7");
let x3 := number(x2);
agestest := x3;
'Grade Level(s)' := agestest
if contains('Request Ages', "2nd Grade") = true then
        let x1 := number(5)
    end;
if contains('Request Ages', "4th Grade") = true then
        let x2 := number(7)
    end;
agestest := x1;
'Grade Level(s)' := agestest

There have been many other variations on these.  So far everything I've tried has either given me nothing or Ninox is interpreting text as numbers that are completely off (for example, I got the agestest field to show 5, 7 as I wanted - the corresponding numbers in the multiple choice field for 2nd grade and 4th grade), but 4 different options in 'Grade Level(s)' were selected without any logic that I have been able to figure out.

Any help would be appreciated.  I feel like there must be something I am missing.

Thanks!

Meghan

3 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    Luckily Ninox allows you to use an array to set multiple choice or dynamic multiple choice fields.

    So if you put something like this in a button:

    let x := [5,7];
    'Grade Level(s)' := x
    

    You will see that 2nd and 4th are selected.

    Take a look at the split() function for help making a string into an array.

    • Meghan
    • 1 yr ago
    • Reported - view

    Thank you Fred!  This gave me that lightning bulb moment.  My short test code for two options works (I'll leave it below, in case it helps anyone else).  Now I just need to expand it to apply to all 18 options.

    let x1 := replace('Request Ages', "2nd Grade", "5");
    let x2 := replace(x1, "6th Grade", "9");
    agestest := x2;
    let x3 := item(split(agestest, " "), 0);
    let x4 := item(split(agestest, " "), 1);
    let x5 := number(x3);
    let x6 := number(x4);
    let myArray1 := [x5];
    let myArray2 := [x6];
    let myArray3 := array(myArray1, myArray2);
    'Grade Level(s)' := myArray3
    

    I'm sure I've done some redundant things in here, so hopefully the final product won't be too long.  I'm sure there's a way to not need the agestest text box as a midway point, and I think the array section could be simplified.  But it finally works after hours of fussing with it.

    • Fred
    • 1 yr ago
    • Reported - view

    Maybe try out:

    let y := split('Request Ages', ",");
    let x := for loop1 in y do
            switch true do
            case loop1 = "1st Grade":
                1
            case loop1 = "2nd Grade":
                2
            case loop1 = "3rd Grade":
                3
            case loop1 = "4th Grade":
                4
            case loop1 = "5th Grade":
                5
            end
        end;
    

    Line 1 converts the Request Ages field into an array. If it doesn’t use a comma to separate items then change it.

    Line 2 - 15 use the for loop command to move through the new array in y and then uses the switch command to swap text for a number and then creates a new array in x.

    You would extend the switch out to encompass all of the possible grades.

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 3Replies
  • 223Views
  • 2 Following