0

Get the number of the chosen entry in a Dynamic Choise field

Hi,

In a normal Choice field you can have a FX field that dispalys the number of the selected choice like this:

number(ChoiceFieldName), then the FX displays 0 if emty, 1 for choice1, 2 for choice2 etc.

 

I cant get similar to work for a Dynamic Choice field. It is set up to be Combobox.

number(DynamicChoiceName) just gives me the Id number for the selecte Record, from the table where the Daynamic Choice has its source.

I have tried using chosen, but this dont seem to be valid for a Dynamic Choice. (function is not defined)

Is there a way to do this? My goal is to create a "Next" button and "Previous" button, so I dont have to use the combobox, if i just quicly want to scroll through the list.

7 replies

null
    • Fred
    • 6 mths ago
    • Reported - view
     said:
    My goal is to create a "Next" button and "Previous" button, so I dont have to use the combobox, if i just quicly want to scroll through the list.

    Just want to make sure I understand what you want, you want to create a button that you can use to make the next/previous selection of a dynamic field? Can you use radio buttons so you can quickly change your selection?

    How many choices show up in the dynamic field?

    What is the dynamic value formula for the dynamic choice field?

      • Haavard_Hjorteland
      • 6 mths ago
      • Reported - view

       

      Yes, that  is what i want, one Next and one Previous button.

      The list can be long, as pr. now close to 100 in some occations, so Radio button take up to much space.

      This all works fine, it just would be handy with Next/Previous buttons.

      Below is the dynamic value formula, with some Nowegian naming I'm afraid  

      This DC named "Velg_Beboer" (Chooce resident)  is based on two previous DC fields, that filter first on County, and then Farmname.

      So "Velg_Beboer" show all the Persons that lived/lives on the selectet farmname.

      the if/else in the code is based on a normal Choice field that allow to filer on Firstname, Lastname and Year.

      The list can be long, if i have many records of persons in a Farm. And as it is dynamic it will grow as i add more records.

      do as server
          let grd := text(Gard);
          let gn := text(GV_F);
          if Beboer_Sortering = 1 then
              (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Beboernr
          else
              if Beboer_Sortering = 2 then
                  (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Person.Fornavn + Person.Farsnavn
              else
                  if Beboer_Sortering = 3 then
                      (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Person.Etternavn
                  else
                      if Beboer_Sortering = 4 then
                          (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by year(Fra)
                      else
                          if Beboer_Sortering = null then
                              (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Beboernr
                          end
                      end
                  end
              end
          end
      end

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

    I have a formula to those 2 buttons but you'll need to adapt them to your requirements:

    prev button:

    let rec := record(Names,number(DynChoice));
    let c := index((select Names) order by Name, rec);
    if c != 0 then
        DynChoice := item((select Names) order by Name, c - 1)
    end

    next button:

    let rec := record(Names,number(DynChoice));
    let c := index((select Names) order by Name, rec);
    let t := cnt((select Names) order by Name) - 1;
    if t > c then
        DynChoice := item((select Names) order by Name, c + 1)
    end

    Here is Names the source table of the choice field.

    Only thing you have to adapt is the select()  to your needs.

    Edit: Just saw that is also involved. Sorry for jumping in, maybe you'll find a neater code... (I know you will 😉)

      • Haavard_Hjorteland
      • 6 mths ago
      • Reported - view

       

      Hurray, this works well, thanks.👍

      First I was using FX fields with the code in On click. Then only the "Previous" worked, not "Next" for some reasons. Then i switched to real Buttons, and both is working fine now.

      The code in my Previos button is:

      let rec := record(Pers_Bydebok,number(Velg_Beboer));
      let c := index((select Pers_Bydebok) order by Bostednr, rec);
      if c != 0 then
          Velg_Beboer := item((select Pers_Bydebok) order by Bostednr, c - 1)

      end

       

      And Next Button:

      let rec := record(Pers_Bydebok,number(Velg_Beboer));
      let c := index((select Pers_Bydebok) order by Bostednr, rec);
      let t := cnt((select Pers_Bydebok) order by Bostednr) - 1;
      if t > c then
          Velg_Beboer := item((select Pers_Bydebok) order by Bostednr, c + 1)
      end

    • Fred
    • 6 mths ago
    • Reported - view
    Haavard Hjorteland said:
    The list can be long, as pr. now close to 100 in some occations, so Radio button take up to much space.

    Wow that is a long list. FYI, dynamic fields only show you the first 100 records, so if you ever get over that then you will not see all of the records.

    If you use a reference field, set to pop up, you can see all related records and also search on data.

    For you code, have you looked into using a switch() command? It would look something like:

    do as server
        let grd := text(Gard);
        let gn := text(GV_F);
        switch Beboer_Sortering
         case 1:
            (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Beboernr
         case 2:
            (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Person.Fornavn + Person.Farsnavn
          case 3:
            (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Person.Etternavn
          case 4:
            (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by year(Fra)
          default:
            (select Pers_Bydebok where Stedsnavn.Stedsnavn = grd and Stedsnavn.'Gnr.2021' = gn) order by Beboernr
        end
    end

     

    wrote:

    Edit: Just saw that is also involved. Sorry for jumping in, maybe you'll find a neater code... (I know you will 😉)

    You can jump in anytime. The more the merrier.

      • Haavard_Hjorteland
      • 6 mths ago
      • Reported - view

      Fred 

      Thank you. When I try your switch command code (copy/paste from your code) i get an error message at line 5 (case 1:)

      symbol expected do, symbol excpected end and end excpected case at line 5.

      I have not explored the switch option much, so I may miss something.

      Regarding the 100 records limit in DC, I myself have DC fields that show thousands of records. Not practical always, but when i select (emty) on top I can easily search. See Image below, where I am only at the middle of the 6000 + Persons Lastname. (the scrollbar is ca. at the middle)

      Regarding the code from RoSoft_Steven , I was a bit quick to say it works well as I first implemented it. It works partly sometimes, but i am working on making the buttons work always.

      I have allmost figuered it out, my problem was probably the order by staement i used.

      The Previous button right now is like this, order by Stedsnavn.BygdebokLink.number(Beboernr) :

      This refere to the selected Stedsnavn (Farm name), witch have a link to Pers_Bygdebok table, and filter on the  'Beboernumber' field witch is 001, 002, 003 etc.

      let rec := record(Pers_Bydebok,number(Velg_Beboer));
      let c := index((select Pers_Bydebok) order by Stedsnavn.BygdebokLink.number(Beboernr), rec);
      if c != 0 then
          Velg_Beboer := item((select Pers_Bydebok) order by Stedsnavn.BygdebokLink.number(Beboernr), c - 1)
      end

       

    • Fred
    • 6 mths ago
    • Reported - view
    Haavard Hjorteland said:
    symbol expected do, symbol excpected end and end excpected case at line 5.

     oops, yes just add do to the end of

    switch Beboer_Sortering do

     

    Haavard Hjorteland said:
    Regarding the 100 records limit in DC, I myself have DC fields that show thousands of records.

    Well what do you know. It use to have a limit. I just tried it out on a 5700 record table and was able to access the last record. And you can search.

    Though I think for myself the reference field is "faster" as you don't have to do a select to fill in the field. But it works so why change it.

Content aside

  • Status Answered
  • 6 mths agoLast active
  • 7Replies
  • 78Views
  • 3 Following