Script for Button for next record, order not ID
Hello,
Could someone help with a script for button switching for next record based not on ID but on 'Ordre Groupe' number field.
if 'Ordre Groupe' then
let nextRecord := first(select 'A053' where 'Ordre Groupe' > 'Ordre Groupe' order by 'Ordre Groupe' asc);
if nextRecord then
openRecord(nextRecord);
else
alert("No records found for Ordre Groupe : " + text('Ordre Groupe'));
end
else
alert("Groupe order undefined or equal to zero");
end
13 replies
-
First you will need to create a variable that stores the current record using the 'this' command. Then modify your where filter to include that new variable so Ninox knows which 'Ordre Groupe' it needs to compare.
Also at line 3. Ninox does accept a sort order command like that.
So something like:
let t := this; if 'Ordre Groupe' then let nextRecord := first((select 'A053' where 'Ordre Groupe' > t.'Ordre Groupe') order by 'Ordre Groupe'); if nextRecord then openRecord(nextRecord); else alert("No records found for Ordre Groupe : " + text(t.'Ordre Groupe')); end else alert("Groupe order undefined or equal to zero"); end
I hope this helps.
-
You can try something like this:
let t := this; if 'Ordre Groupe' then let getrecs := (select 'A053' order by 'Ordre Groupe'); let getIndex := index(getrecs,t); let nextRec := item(getrecs,getIndex+1); let prevRec := item(getrecs,getIndex-1); openRecord(nextRec) else
Here we use the index() to figure out where in the array of all records from A053 that is ordered we are and then use the item() command find the record that is just before or just after the current record. I'm not sure how this code scales, if you have 10,000+ records.
You can change the openRecord to nextRec or prevRec depending on the button.
For your previous button you can put this in the Display only if:
let t := this; let getrecs := (select 'A053' order by 'Ordre Groupe'); let getIndex := index(getrecs,t); getIndex > 0
So if the record is the first in the array then it will not show the previous button.
Then for the next button you can do:
let t := this; let getrecs := (select 'A053' order by 'Ordre Groupe'); let getIndex := index(getrecs,t); let getCount := count(getrecs); getIndex < getCount
Now the next button will not show if you are on the last record of the array.
-
Hello Fred !!
Thank you so much for the new script. I installed and ran it but the popup form where are located the "previous" and "next" buttons un-pops (closes) sporadically. So sometimes the "next" button works, sometimes it doesn't and closes the Ninox_auto-form.
Maybe an idea :
The error could because of the views on the top that filter records based on days of the week (Lu = Monday, Ma = Tuesday, Me = Wednesday, Je = Thursday, Ve=Friday, Sa = Saturday, Di = Sunday). So probably because each top view selects only a portion of the DB, whenever the click on "next" button and the "Ordre Groupe" doesn't belong to the fileter of the view (for ex : Lu>0), then the popup gets "upset" and hides itself and shows no active record in the selected top view.
This intuition is corroborated by the fact that if I am on the top view called "ALL ACTIVE" (which applies no filter and therefore show all records ordered by 'Ordre Groupe', then the next button works perfectly on many records (probably all). Probably because the order in DB is the same as the items shown in the view.
Would it be possible to "adapt" the navigation buttons so that they consider the items listed in the filter of the active view ? Instead of navigating according to the unfiltered items ? (Not sure I am clear on this...let me know).
As a reminder : This one table DB can be split into a relational model, but first, I am building experience with a one-table DB (repetitions are few).
This DB is intented to be used by people who distribute newspapers and Magazines to Villas in south of France. Depending on the day of the week, the route is different and follow subsriptions and subsribers for adequate deliveries by delivery men.
Please find attached an anonymized excel version of the entire table (the volume of the table will vary very slightly and never be greater than 300 records.
Again, venerable Fred, thank you sooo much for your help and advice. BTW if you have some suggestions on how to improve the process, (like for example the tip you gave me on selecting the actual record : "this". Great !)
My next step, when the navigation buttons are fixed is to probably Manage everything from a NINOX "page" where I'll put a view of 4-5 upcoming deliveries, with clients Names and locations, and put my buttons, etc... So that delivery men only see one page. A sort of Execution and Dashboard guide.What you think ? Could this be a good approach ?
Sorry for the length of the message. But i put so much energy to feel comfortable with Ninox that I really want to make it work.Best to you,
Jean-Stéphane
-
said:
Would it be possible to "adapt" the navigation buttons so that they consider the items listed in the filter of the active view ? Instead of navigating according to the unfiltered items ? (Not sure I am clear on this...let me know).Not directly, because Ninox can not tell what view you are on so you can't pass along the name of the view along.
said:
So that delivery men only see one page. A sort of Execution and Dashboard guide.If you are making a DB for others to use then I always recommend that you limit their interactions with the raw data. So I wouldn't spend much more time on this button issue and work on your dashboard. Once you have your dashboard then you will have more information to work with.
-
said:
Not directly, because Ninox can not tell what view you are on so you can't pass along the name of the view along.Hello Fred!
ok, but how would it be possible to do it? In case I build a dashboard, I'd like to have navigation buttons which can take in consideration the view I am on. What are the workarounds. Navigating buttons are a Must have with users, absence of navigation buttons will not be understood.
Thank you for your lights on this. -
I created a test DB but have encountered an issue.
If you open Page1, and select a record from the view you will see a few buttons on top. If you click on precedent or suivant buttons you see nothing change, but if watch on the table list you have changed locations to the A503 table.
If you keep clicking on either button nothing seems to happen. But in the background the app is moving to the next/prev record. You can see this when you close the record. You will see the record now that you have closed the record from the view.
I don't know if others are encountering this issue.
I was thinking one could use the onclick function in Ninext to redirect to another Page that you can use to get the data.
This seems like a bug to me and I'm submitting to Ninox.
I have a work around.
Back to Page1, select a Day. Click on Button button.
It will now take you to the A053 table and to the appropriate view as well. Now the precedent and suivant buttons will take you through the appropriate filtered records.
Users can press the Return button to return to Page1 to change their view.
-
Dear Fred,
Thank you for the final script.
I have questions : "DeliveryDays" and "Select a Day" should be replaced by field names or left just like that?Many thanks,
js
Content aside
-
1
Likes
- 9 mths agoLast active
- 13Replies
- 257Views
-
2
Following