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
-
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.
-
Also know that a yes/no field has 3 states.
Yes, No and null. -
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?
-
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?
-
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.
-
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
Content aside
- Status Answered
- 1 yr agoLast active
- 12Replies
- 200Views
-
3
Following