0

How to create a button that clicks through forms

I'd like to put a button on the first tab of my form that, when clicked, opens the next record down on the table. The same as using the down-arrow on the keyboard. What script would i need for the button? Thanks!

15 replies

null
    • Nick
    • 6 yrs ago
    • Reported - view

    Next Record:

    let thisNUM := number(Id);
    let myNUM := min((select yourTable)[number(Id) > thisNUM].number(Id));
    openRecord(record(yourTable,myNUM))

     

    Previous Record:

    let thisNUM := number(Id);
    let myNUM := max((select yourTable)[number(Id) < thisNUM].number(Id));
    openRecord(record(yourTable,myNUM))

     

    These buttons works right when table sorted by Id.

     

    Nick

      • Kruna
      • 1 mth ago
      • Reported - view

       looking for my issue I came across this post.

      I Need some help please, as I cant figure out, how the Script would be when I would Click next record in subtable?

      I tried with select yourtable.subtable, but it doenst work.

      thnx

      • Fred
      • 1 mth ago
      • Reported - view

      is the "next" button in the "subtable"? I put it in quotes because when you are in the record of the subtable then the "subtable" is now THE table. You can use the reference field back to parent table to get the records that in the subtable.

      let t := this;
      let allSubtableRecs := parentTable.subtable;
      let countSubtableRecs := length(allSubtableRecs);
      let currentIndex := index(allSubtableRecs,t);
      let nextRec := item(allSubtableRecs, currentIndex + 1);
      popupRecord(nextRec)
      

      You don't need line 3 for this part of the code. I was thinking I would use this to do some checking to make sure where you are in the array. But I thought it would be better to use it in the Display only if and hide the button when it is not needed.

      I used popupRecord() because openRecord() didn't do the right thing for me.

      • Kruna
      • 1 mth ago
      • Reported - view

       hi Fred, yes I forgot to mention that the button has to be in Main table, I mean parent table.

      I tried your script, but it just opens the First record of the subtable.

      thnx

      • Kruna
      • 1 mth ago
      • Reported - view

       edit:  I dont get the second line to work.😅

      • Fred
      • 1 mth ago
      • Reported - view

      yes I forgot to mention that the button has to be in Main table, I mean parent table

      Then that would mean you have to close the child record to open the next one. My script is for a button in the child table.

      I dont get the second line to work.

      Since my script starts in the child table, you just need to remove the parentTable reference if you are in the parent table.

      • Kruna
      • 1 mth ago
      • Reported - view

       yes, I have an Script for the Button in Child table, but how would be the Script for parent table?

      Thnx

      • Fred
      • 1 mth ago
      • Reported - view

      I'm not sure why you would have a button at the parent table. Once you open a child record, it would seem like to me that the Next button should be there.

      But if you really want it in the parent table then you need a number field to track which record you are on. I created one called currSub with a default value of 0. Then your code could look something like:

      let allSubRecs := subTableField;
      if length(allSubRecs) = currSub then
          currSub := 0
      end;
      popupRecord(item(allSubRecs, currSub));
      currSub := currSub + 1

      Line 1, creates an array of the child records.

      Lines 2 - 4, checks to make sure that we don't go over the number of linked records.

      Line 5, popups the item in the array according to the number in currSub, starting with 0 and going up from there.

      Line 6, increases the value in currSub by 1 every click of the Next button.

    • David
    • 6 yrs ago
    • Reported - view

    Thanks, Nick. I'll try it out. 

    • David
    • 6 yrs ago
    • Reported - view

    Nick, does it also work if the table is sorted by something else (like country names on a dropdown or alphabetically by text)?

    • Sean
    • 6 yrs ago
    • Reported - view

    I don't know if this is still relevant, but this is a solution I came up with for sorted views.

     

    Next Record:

    let txtThisName := NameField;
    let aryNames := (select Table1)[NameField > txtThisName].NameField;
    let arySortedNames := sort(aryNames);
    let numNextId := min((select Table1)[NameField = item(arySortedNames, 0)].number(Id));
    if cnt(arySortedNames) != 0 then
    openRecord(record(Table1,numNextId))
    else
    alert("End of Table")
    end

     

    Previous Record:

    let txtThisName := NameField;
    let aryNames := (select Table1)[NameField < txtThisName].NameField;
    let arySortedNames := rsort(aryNames);
    let numNextId := min((select Table1)[NameField = item(arySortedNames, 0)].number(Id));
    if cnt(arySortedNames) != 0 then
    openRecord(record(Table1,numNextId))
    else
    alert("Beginning of Table")
    end

    • Nick
    • 6 yrs ago
    • Reported - view

    All these are workarounds that doesn't work right.

    Lets's hope Ninox Team add the functions

    goToRecord (Next)

    goToRecord (Last) etc.

    The code is already hard coded to the app.

    Screen Shot 2018-10-02 at 22.23.21

    Nick

    • Sean
    • 6 yrs ago
    • Reported - view

    Hey Nick, I'm confused. You seem a little hostile and you responded with a workaround yourself. I simply thought it was an interesting exercise and I am aware that those navigation controls exist. The OP has started many threads that are somewhat misguided and could be cleared up by taking some time to learn how develop a database properly.

     

    Oh yeah, the code works. Just sayin'

    • Nick
    • 6 yrs ago
    • Reported - view

    No, no hostile at all! Don't get me wrong.

    I love the app, and (as you said about my responce) I'm trying to help other users.

    I just say that I am not completely satisfied (my workaround included). And as I try to find solutions that could be simple.

    And of course I love exercises too!

     

    Nick

    • Sean
    • 6 yrs ago
    • Reported - view

    Cool. I enjoy working with the app also and I'm looking forward to the next release which will hopefully include some of the enhancements we have been asking for.

    I know my workaround is ugly, but I had fun making it happen anyway.  ;)

     

    Sean

Content aside

  • 1 mth agoLast active
  • 15Replies
  • 3682Views
  • 3 Following