0

JSON in dynamic fields

So I've been testing out the new JSON in dynamic fields and ran into a few issues. I emailed Ninox and got this response:

Thank you for reaching out and for sharing the details about your use of JSON in dynamic choice fields.

To address your inquiry:

  1. Ninox provides the option to use JSON and HTML for advanced customizations, including dynamic choice fields.

     

  2. However, please note that this functionality is offered without official support. Implementing and managing it will be at your own responsibility.

If you have any additional questions, feel free to ask!

Huh? Wasn't this a major feature in 3.14?

Here was my original email:

Playing around with JSON in dynamic choice fields.

 

1) If I build it using something like:

 

for i from 1 to 13 do 

{

id: i,

caption: text(date(2024, i, 1))

}

end

 

It works fine in choice and multichoice. I can do number(s) and get the selected choices.

 

text() does not return anything. Is that normal? Is there anyway to get the caption data?

 

2) If I build the JSON using data from another table or two, and use the recID. Ninox builds the dynamic field but when I try using number(s) I get nothing returned. 

 

What are the current limiations with JSON data in dynamic fields?

 

Thanks,

What have others encountered with the new dynamic field function?

31 replies

null
    • szormpas
    • 1 mth ago
    • Reported - view

     Hi, I've just started using the new toy!

    It looks like you can get the caption by referring to the field name without the text().

    raw('Choice (dynamic)') gives the id as a string.

    number('Choice (dynamic)') gives the id as a number.

    • szormpas
    • 1 mth ago
    • Reported - view

     

    I might be wrong, but as far as I understand the dynamic choice field always converts the id to a string.

    The number() function can't translate something like "A1" to a number, but it can do that with an id like "1".

    • Fred
    • 1 mth ago
    • Reported - view
     said:
    It looks like you can get the caption by referring to the field name without the text().

    Well what do you know.

    But if you do a debugValueInfo() on a dC or dMC then you get something like:

    dchoice("C7")
    
    or
    
    dmulti("f1")
    

    not very helpful is you need to use the data. It doesn't really return the caption value in a useful form.

    raw() only seems to work for choice fields. multichoice doesn't return an array of choices. So you can modify the Id to:

    for rec in getTableA do
        {
            id: number(rec.Id),
            caption: sum(rec.Score)
        }
    end
    

    Then you can get something useful.

    • szormpas
    • 1 mth ago
    • Reported - view

    Hi, I'd like to go into this a bit more.

    It looks like the dynamic choice field is set up to accept unique strings for IDs, so we can use something like:

    [{
            id: "Apple",
            caption: "Apple"
        }, {
            id: "Banana",
            caption: "Banana"
        }, {
            id: "Watermelon",
            caption: "Watermelon"
    }]
    

    In the above case you can get the values by using raw(), string() or just the name of DC field.

    On the other hand, if we put the above JSON into a dynamic multiple choice, we can see the captions, but we can't make any choice. It seems like a bug to me!

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 mth ago
      • Reported - view

       

      On App Android in this case don't work, don't display anything.

      • szormpas
      • 1 mth ago
      • Reported - view

       Hi, you mean it doesn't work for both simple and multipe choice fields?

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 mth ago
      • Reported - view

       Yes doesn't work in both

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 mth ago
      • Reported - view

       

      [{
              id: 1,
              caption: "Rev A",
              color: "yellow"
          }, {
              id: 2,
              caption: "Rev B",
              color: "green"
          }, {
              id: 3,
              caption: "Rev 0",
              color: "blue"
          }]
    • szormpas
    • 1 mth ago
    • Reported - view

    So far, the JSON functionality in dynamic multiple choice fields need the 'id' property to be a number and we can get the choices by using the numbers() function.

    I try to understand how does this really differ from what we already get from the simple multiple choice field.

    Can anyone provide us with a use case that we really need this new JSON functionality?

      • Fred
      • 1 mth ago
      • Reported - view

      One way, if I needed a choice field of all years in a table (i.e. my invoice tables). You could create a static list, but then you have to update it every year.

      • Fred
      • 1 mth ago
      • Reported - view

      Another case would be to make a choice list that is modifiable by end users through a script without having to create a new table.

    • szormpas
    • 1 mth ago
    • Reported - view

    I was asking Andy from Nioxus about this in his webinar today and, if I've understood correctly, he said that using JSON means you lose the 'dynamic' feature for the selection field.

    • szormpas
    • 1 mth ago
    • Reported - view

     Hi,

    It looks like the text (myChoiceField) isn't working as it should because of a bug.

    I posted the issue on the German Ninox forum and got a reply from Uwe (Ninox support):

    https://forum.ninox.de/t/60yzncq/json-in-dynamic-choice-field

      • Fred
      • 1 mth ago
      • Reported - view

      Ninox initial response to my question was that they don't support JSON. When I wrote back they got back to me a couple of days ago, which I missed and they said the same thing.

      Anyways, thanks for posting in the German forum. It must be nice for them to have Frank respond.

      • szormpas
      • 1 mth ago
      • Reported - view

         

      I'm really not sure why Ninox doesn't merge the two forums. With the automatic translation feature that browsers now provide, it would be easy for everyone to get involved.

      It looks like Ninox is more involved in the German forum at the moment. For instance, the announcement of the release of version 3.14 was made on the German forum, but not on this one – unless I've missed it.

      • Ninox partner
      • RoSoft_Steven.1
      • 10 days ago
      • Reported - view

         Seems like the bug "text( MC)" is solved with the version 3.14.1

      • szormpas
      • 10 days ago
      • Reported - view

       Great!

      • Fred
      • 10 days ago
      • Reported - view

      I don't see any changes. when I do text(dMC) I get a blank formula field. If I do just dMC then it shows the selections. If I do debugValueInfo(text(dMC)) it shows string("").

      • Ninox partner
      • RoSoft_Steven.1
      • 9 days ago
      • Reported - view

      Are you on version 3.14.1 ? It works on my end though?

      • Fred
      • 9 days ago
      • Reported - view

      I'm in public cloud, so yes.

      Here is what it looks like:

      • Ninox partner
      • RoSoft_Steven.1
      • 9 days ago
      • Reported - view

       Strange, I get this but I'm on private cloud using chrome browser.

      • Fred
      • 9 days ago
      • Reported - view

      Here is my json code:

      let originalFruit := split(originalChoices, ", ");
      for i in range(1, count(originalFruit) + 1) do
          {
              id: i,
              caption: item(originalFruit, i - 1)
          }
      end
      

      which gives me:

      and it is this field that I put in my dynamic choice fields.

      and

    • szormpas
    • 1 mth ago
    • Reported - view

    Hi Fred,

    Do you know if there's a way we can feed the dynamic choice field with a JSON object programmatically (via Ninox scripting)?

    For instance, by clicking a button.

      • Fred
      • 1 mth ago
      • Reported - view

      Playing around I figure out this long way.

      I start with five items.

      1. formula field that builds my JSON
      2. a text field called originalChoices
      3. a text field called newChoice
      4. a button
      5. a dynamic choice field that uses the formula field from 1

      Here is formula in the formula field:

      let originalFruit := split(originalChoices, ", ");
      for i in range(1, count(originalFruit) + 1) do
          {
              id: i,
              caption: item(originalFruit, i - 1)
          }
      end

      here is what it looks like at the start:

      Here I am adding a new choice:

      And here it is after adding:

      Here is the code for the Add Choice button:

      let x := originalChoices;
      let y := if not contains(originalChoices, newChoice) then
              originalChoices + ", " + newChoice
          end;
      if y != null then originalChoices := y end;
      newChoice := null

      There is a bit of error checking but not very robust.

      I'm sure someone smarter will come up with a quicker way, so I look forward to it.

      • red_kite
      • 1 mth ago
      • Reported - view

       Hi. For example, through a text field in which the values are separated by commas. Then the code in dchoicefield. 

      let caption := split(Text, ",");
      let dynamicJSON := [{}][null];
      for i in range(cnt(caption)) do
          let object := {};
          setItem(object, "id", i + 1);
          setItem(object, "caption", item(caption, i));
          dynamicJSON := array(dynamicJSON, [object])
      end;
      dynamicJSON
      

Content aside

  • 9 days agoLast active
  • 31Replies
  • 215Views
  • 6 Following