0

Yes/No function

Hi,

I want to change my multiple choice function to several yes/no functions. All works well but one choice. I want to use a yes/no function (named OHW) to indicate that a client is no longer an active client and if so, the date of the last session will become visible. This works with the multiple choice function in the code I put in the last-session function field:

let i := this;
let s := (select Sessies);
let n := Sessies.'S-nr';
if chosen('Coachees tab', [1]) = false then
    s = i;
    last(n);
    date(last(Sessies.Sessie))
end

But now if I change the "chosen('Coachees tab', [1])" to OHW=false it doesn't work: I get no more data display in the last-session function field although the dates are still in the database.

The last-session field will only be visible with the "Display field only, if chosen('Coachees tab', [1]) = false". I experimented with that and it doesn't work there either.

Same goes for another yes/no function (named Afspraken): If I add a record from a sub-table (named Begeleidingsafspraken), I want the yes/no function to go from NO to YES. To add a record in the subtable I have this code (which works very well) in a button which I also use to open the sub-table record.

let s := this;
if Begeleidingsafspraken = null then
    let n := NR;
    let a := s.Email;
    let t := number(Begeleidingsafspraken.Nr);
    let newCA := (create Begeleidingsafspraken);
    Afspraken = true;
    newCA.(
        Coachees := s;
        t := n;
        Email := a
    );
    popupRecord(newCA)
else
    let myRec := (select Begeleidingsafspraken where Coachees = s);
    popupRecord(last(myRec))
end

So: how do I exchange the multiple choice field to a yes/no function in the code and how do I change yes/no automated?

Thanks for your help

Marjolijn

12 replies

null
    • Fred
    • 6 mths ago
    • Reported - view

    A couple of questions:

    let i := this; let s := (select Sessies); let n := Sessies.'S-nr'; if chosen('Coachees tab', [1]) = false then s = i; last(n); date(last(Sessies.Sessie)) end

    In line 2 you do a select of the Sessies table and put the returned values in a variable (s).  Then in line 5 you set the variable (s) to equal the variable (i), which wipes the results of the select you just did. If you don't need the select I would recommend that you get rid of line 2. You want to try to reduce the use of select statements.

    Line 3, shows me that you have a relationship field called Sessies. You then set a variable (n) to equal the array of data that is in the 'S-nr' field of all related records through the Sessies relationship. Then in line 6 you get the last item in the array. Then you do nothing with the variable. If you don't need the value then I would recommend removing any reference to (n) so you can make your code cleaner and faster.

    In addition since you have relationship field you don't need to do a select. Another reason to get rid of Line2. Unless you need access to all records from Sessies not just related records.

    So you could simplify your code to something like:

    if OHW = false then
        date(last(Sessies.Sessie))
    end
    

    What kind of field is Sessie?

    You could test out the if statement:

    if OHW = false then "false" end
    

    If this works then there is something up with your code getting the date.

      • mpm
      • 6 mths ago
      • Reported - view

      Fred Sessies is the table with reports and session dates (field called Sessie) per client. Sessies is a sub-table to the Coachees table which contains only the basic patient information. So I have multiple clients with each multiple sessions. In the Coachees table I need the date of the last session filled in with that one client after he/she finished the treatment/sessions.

      Unfortunately your suggested code would give me just the last date from the array of all sessions from all no-active clients.

      The code I wrote works fine with the Multiple Choice but doesn't with the yes/no. Just fyi: OHW just means Work At Hand.

    • Ninox partner
    • RoSoft_Steven.1
    • 6 mths ago
    • Reported - view

    Also know that a yes/no field has 3 states.
    Yes, No and null.

      • mpm
      • 6 mths ago
      • Reported - view

       Yes, I surely do

    • Fred
    • 6 mths ago
    • Reported - view
     said:
    Unfortunately your suggested code would give me just the last date from the array of all sessions from all no-active clients.

     Looking back now, I have completely mis-read your code. (now where is that delete feature?)

    Plus I don't know why the first code block formatted as a long string and not in lines.

    Is there anyway you can upload a sample DB with dummy data?

      • mpm
      • 6 mths ago
      • Reported - view

       sure I can. I still got the one multiple choice field active (the OHW I want to lose) as well as the yes/no OHW (I want to keep). Clicking them will show you the difference concerning the visibility and filling of the 'Laatste sessie' field in the Coachees table.

      My second code block concerns the 'Begeleidingafspraken' sub-table. If 'Begeleidingsafspraken' is made (so !=null), the yes/no 'Afspraken' would need to go to yes. But it doesn't ...

    • Fred
    • 6 mths ago
    • Reported - view

    So I changed the code to:

    let i := this;
    let s := (select Sessies);
    let n := Sessies.'S-nr';
    if OHW = false then
        s = i;
        last(n);
        date(last(Sessies.Sessie))
    end

    And when OHW is false I get:

    And when it is true, I get:

    Which is what you wanted?

    • Fred
    • 6 mths ago
    • Reported - view

    I also tried cleaning up the code to:

    if OHW = false then
        date(last(Sessies.Sessie))
    end
    

    And the same data is presented as with your code.

    let i := this;
    let s := (select Sessies);
    let n := Sessies.'S-nr';
    if OHW = false then
        s = i;
        last(n);
        date(last(Sessies.Sessie))
    end
    

    Line 5, you asks Ninox to compare the array in (s) to the rid in (i) and Ninox will always return "false" since an array with multiple values will probably never equal the rid of the current record. Then you do nothing with that information.

    Line 6, you ask Ninox to get the last value in the array created in (n). Then you do nothing with that information.

    Since Line 7 the last command that is the command that is displayed by Ninox. Now I know why you have the date() command around Sessie. Sessie is an appointment field.

      • mpm
      • 6 mths ago
      • Reported - view

       I had to make a new "Laatste Sessie" field to make your code work. Somehow adjusting the field code gave no result (null) in the old field. With the new field it works like clockwork. I don't know why because the Sessies-table is not a subtable but it's the result that matters. Thank you!

      • Fred
      • 6 mths ago
      • Reported - view

       That is weird.

      If you look in the Coachees table, on the Sessies en Fracturn tab you will see a field called Sessies. This is the relationship view table created by Ninox from the relationship field to Coachees in your Sessies table.

      When you get a chance please mark the post answered. :)

    • Fred
    • 6 mths ago
    • Reported - view

    The answer to your second part is you forgot the ":" in front of the "=" sign for Afspraken, line 7. Easy thing to do in Ninox. To set fields to a value you use ":=". If you have a plain "=" then you tell Ninox to evaluate if the field equals the value.

    let s := this;
    if Begeleidingsafspraken = null then
        let n := NR;
        let a := s.Email;
        let t := number(Begeleidingsafspraken.Nr);
        let newCA := (create Begeleidingsafspraken);
        Afspraken := true;
        newCA.(
            Coachees := s;
            t := n;
            Email := a
        );
        popupRecord(newCA)
    else
        let myRec := (select Begeleidingsafspraken where Coachees = s);
        popupRecord(last(myRec))
    end
    
      • mpm
      • 6 mths ago
      • Reported - view

       Silly me for not seeing that one in advance ... thank you for correcting my error and all your help :-)

Content aside

  • Status Answered
  • 6 mths agoLast active
  • 12Replies
  • 134Views
  • 3 Following