0

2 multiple choice creat records ?

In ninox I have two TABLEs
The fields of table1 include: household (multiple choice), for example, A01.A02....
                                 Floor (multiple choice) fields, such as 02F.03F.....
The fields of table2 are: unit1(TEXT)
                                  floor1(TEXT)
                                  unitfloor(TEXT)

Requirement: I want to select A01 02F 03F in table1. Table2 will automatically create A01 02F A01-02F and A01 03F A01-03F. If 03F is canceled, A01 03F A01-03F will be deleted and only A01 02F A01-02F will be left.

How to create such a relationship

thanks

2 replies

null
    • Fred
    • 5 mths ago
    • Reported - view

    It was quite an interesting task to figure out. You can put the following in a button to test it out:

    "takes the selections from the multiple choice fields
    and creates a string for each combination of unit/floor
    selected";
    let unitArray := chosen(unit);
    let floorArray := chosen(floor);
    let newCombo := for loop1 in unitArray do
            for loop2 in floorArray do
                loop1 + "/" + loop2
            end
        end;
    "turns the string into an array. We love arrays";
    let x := split(concat(newCombo), ",");
    "get all records from Table2";
    let getAll := (select Table2);
    "find all matching records";
    let matchFloor := for loop1 in x do
            let findSlash := index(loop1, "/");
            let fir := substr(loop1, 0, findSlash);
            let sec := substr(loop1, findSlash + 1);
            let withFloor := getAll[unit1 = fir and floor1 = sec];
            withFloor.number(Id)
        end;
    "takes results from above and compares it
    to all records and creates an array
    of records that exclude the array from above";
    let noMatchFloor := getAll[var n := Id;
            count(matchFloor[= n]) = 0];
    "deletes the new array";
    delete unique(noMatchFloor);
    "create records for unit/floor not existing
    in Table2";
    for loop1 in x do
        let findSlash := index(loop1, "/");
        let fir := substr(loop1, 0, findSlash);
        let sec := substr(loop1, findSlash + 1);
        let unitFilter := getAll[unit1 = fir and floor1 = sec];
        if count(unitFilter) = 0 then
            (create Table2).(
                unit1 := fir;
                floor1 := sec
            )
        end
    end
    

    If everything works like you want, you can move the code into the Trigger after update for the floor field.

      • cyan_silver
      • 5 mths ago
      • Reported - view

       
      Thank you very much for your help

Content aside

  • 5 mths agoLast active
  • 2Replies
  • 42Views
  • 2 Following