0

Create records after checks on three fields

Hi!

 

I have three tables 

 

Tab2 is a fixed table with the following fields:

Text Tab2: text field

Choice1 - 2: choice field between two options

Colour: dynamic choice field

Name: dynamic choice field

Text Copy: text field

 

Tab1 is a table where the user inserts records. These fields:

Text Tab1: text field

Choice1 - 2: choice field between two options

Colour: dynamic choice field

Name: dynamic choice field

Bottom One: button that verifies and creates new records in Tab3

Bottom Two: button that verifies and creates new records in Tab3

Bottom Three: button that verifies and creates new records in Tab3

 

Tab3 is a table that I have to populate with one of the buttons in Tab1. These fields

Text Tab1: text field

Text Tab2: text field

Choice: text field

Colour: text field

Name: text field

 

That’s what the three buttons should do

 

Bottom One creates new records in Tab3 as many as the Tab2 records that pass these checks:
Tab1.Choice1 - 1 = Tab2.Choice1 - 2
and
Tab1.Colour = Tab2.Colour

 

Bottom Two creates new records in Tab3 as many as the Tab2 records that pass these checks:
Tab1.Choice1 - 1 = Tab2.Choice1 - 2
and
Tab1.Colour = Tab2.Colour
and
Tab1.Name = Tab2.Name

 

Bottom Three creates new records in Tab3 as many as the Tab2 records that pass these checks:
Tab2.Choice1 - 2 = 1
and
Tab1.Colour = Tab2.Colour
and
Tab1.Name = Tab2.Name

 

What is the best code for each of these buttons?

I’m probably asking too much. I’m trying to accomplish this with so many chained ifs and I don’t know if it’s okay.

What are the best features I can use in these cases?

 

I enclose the DB Ninox that resumes all this.

Thanks!

2 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    My first step in trying to test out my filtering code is to first test it out without the new record creation so I can double check that I'm getting the correct result.

    Try creating a new formula field (I called my B1_gather) and put this in it:

    let t := this;
    let xClr := record(Colour,number(Colour));
    let xName := record(Name,number(Name));
    let x := (select Tab2)['Choice1 - 2' = t.'Choice1 - 1' and (var tClr := numbers(Colour);
                count(tClr[= xClr]) > 0)];
    concat(x)
    

    Line 1 puts the current record into a variable (t).

    Line 2, since Colour is a dynamic choice field, we will create a variable to store the record of the the selection. This is so we have access to all of the record info in case we need it. It could be a bit overkill but I always like having more info than less.

    Line 3 does the same as line 2 but for the Name field. Not used in this case.

    Lines 4-5 puts the select statement into a variable. As you can see from the filtering we have to do a bit of extra work since Colours (and Name) in Tab2 is a dynamic multi choice field. First we create a variable to put the selections in the Colours field from the record in Tab2. Then we compare it the value we have stored in the variable from Line 2 and we only keep count of selections that have a count greater than 0.

    Line 6 uses a concat to show the record Id of the records that match our filtering. Without it Ninox displays and empty box even when there is info.

    Now that I have tested my filtering and verified that it is working properly, I can then modify Button One to:

    let t := this;
    let xClr := record(Colour,number(Colour));
    let xName := record(Name,number(Name));
    let finalselect := (select Tab2)['Choice1 - 2' = t.'Choice1 - 1' and (var tClr := numbers(Colour);
                count(tClr[= xClr]) > 0)];
    for loop1 in finalselect do
        let newRec := (create Tab3);
        newRec.(
            'Text Tab1' := t.'Text Tab1';
            Choice := text(t.'Choice1 - 1');
            Name := xName.Name;
            Colour := xClr.Colour
        )
    end
    

    Lines 1 - 3 are the same as before.

    Line 4 I changed the variable name to finalselect.

    Lines 6 - 14 is the for loop command that will take the results of finalselect and

    1) create a new record in Tab3 for each item in finalselect

    2) modify the listed fields in Tab3 to match the data in Tab1

    I've uploaded the DB with my changes. I've done B1_gather, B2_gather, and B3_gather and the Button One code. Try creating the code for Button Two and Button Three and let us know how it goes.

    • Web_Namer
    • 2 yrs ago
    • Reported - view

    Fred You gave me a great help! Thank you very much!
    I studied it and now I’m apply it!

Content aside

  • Status Answered
  • 2 yrs agoLast active
  • 2Replies
  • 69Views
  • 2 Following