1

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

null
    • Fred
    • 10 mths ago
    • Reported - view

    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.

      • LionKingIsBack
      • 10 mths ago
      • Reported - view

       

      Hello Fred, 

      First, Thank you soooo much for having spent some seconds reviewing my problem and sending me the correct script.

      I tried it.  It worked for the first 3 records and the stopped (the form lost focus and un-popped) and I couldn't make it work again.  Strange, maybe something with the cache?

      A view selects a active list or 'Ordre Groupe' numbers and buttons "Previous" and "next" should be placed on the auto generated form and help navigate through records selected by the view.

      Form appears when i click on one line :

      Thank you so much in advance if we could sort this out.

      For the moment, it worked 3 times and then, the form loses focus (retracts, dissapears)

      Js

      • Fred
      • 10 mths ago
      • Reported - view

       can u upload a test, with no personal data, DB ?

    • Fred
    • 10 mths ago
    • Reported - view

    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.

    • LionKingIsBack
    • 9 mths ago
    • Reported - view

    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
     

    • Fred
    • 9 mths ago
    • Reported - view
     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.

    • LionKingIsBack
    • 9 mths ago
    • Reported - view
     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.

    • Fred
    • 9 mths ago
    • Reported - view

    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.

      • Fred
      • 9 mths ago
      • Reported - view

      Well, Ninox recommend that I use the closeRecord() command to take care of the issue. I tested and it works. So you can add the command to buttons so it will close the record from the view and the open the record from the table.

      • LionKingIsBack
      • 9 mths ago
      • Reported - view

       Thank you sooo much ! 
      I am not sure I fully understand all. Also, I don't know how to use/open/see  your file .ninox
      Would it be possible to get the full appended script for buttons "Next" and "Previous" please, so I cn study the logic?

      Many thanks ,

      Js

      • Fred
      • 9 mths ago
      • Reported - view

      Thankfully it is just putting the closeRecord() command right before the openRecord() command. The suivant buttons would look like:

      let xdsh := record(Page1,1);
      let t := this;
      let getRecs := ((select A053 where contains(numbers(DeliveryDays), number(xdsh.'Select a Day'))) order by 'Ordre Groupe');
      let getIndex := index(getRecs, t);
      let nextRec := item(getRecs, getIndex + 1);
      let prevRec := item(getRecs, getIndex - 1);
      closeRecord();
      openRecord(nextRec)
      
    • LionKingIsBack
    • 9 mths ago
    • Reported - 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

      • Fred
      • 9 mths ago
      • Reported - view

      DeliveryDays and Select a Day are field names. I created DeliveryDays to make it easier to search on which days has a delivery. You currently have 7 fields (for each day of the week) and to have to search each field would complicate the filter.

      Select a Day is needed as you need to have some reference point to search for a day of the week.

      You can change them to whatever you want, but you will need these two fields for the code to work.

Content aside

  • 1 Likes
  • 9 mths agoLast active
  • 13Replies
  • 257Views
  • 2 Following