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
    • 3 wk ago
    • Reported - view

         Hi, I really appreciate your input.

    After hours of trial and error and with the help of your contribution, I have finally found a simple and sustainable solution.

    Inside the Text field the JSON string needs to be exactly as below:

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

    Once we're inside the Dynamic Choice Field, we'll need to reconstruct the JSON object:

    for i in parseJSON(Text) do
        {
            id: i.id,
            caption: i.caption
        }
    end
    
    • Fred
    • yesterday
    • Reported - view

    Looks like there is difference between how you build your JSON that affects the ability of Ninox to use text().

    This code works:

    for i from 1 to 13 do
        {
            id: i,
            caption: text(date(2024, i, 1))
        }
    end
    

    I get:

    But this code doesn't work:

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

    I finally worked out is that the array of fruit names is not hard coded in the dynamic field. I'm getting the fruit names from the field originalChoices. This was setup to allow for end users to modify the dynamic field so there had to be a field that stored the values.

    If I switch it to:

    let fruitArray := ["Lychee", "Plum", "Peach", "Apple"];
    for i from 1 to count(fruitArray) + 1 do
        {
            id: i,
            caption: text(item(fruitArray, i - 1))
        }
    end
    

    I get:

    So until Ninox fixes this, it is another limitation of the new JSON dynamic fields.

      • szormpas
      • yesterday
      • Reported - view

        Hi, you are right. I've just checked the text(dMC) and come to the same conclusion. The text() function only works if the JSON object is hardcoded into the dynamic field, which is a big limitation.

    • John_Halls
    • 13 hrs ago
    • Reported - view

    Hi  I think the problem with

    let originalFruit := split(originalChoices, ", ");
    

    is that it gives the ability to have different dmc values for different records in the same table, which might not be correct. Swap it out with

    let a := first(select Table1).originalChoices;
    let originalFruit := split(a, ", ");
    

    forcing a single value per table and text(dmc) works.

    Regards John

      • szormpas
      • 12 hrs ago
      • Reported - view

        Hi,

      Thanks for explaining that. So, when it comes to the text() equation, we've got to use a select statement or the record() function to reference the dynamic JSON object, not just a direct reference to the field.

    • Fred
    • 10 hrs ago
    • Reported - view
     said:
    is that it gives the ability to have different dmc values for different records in the same table, which might not be correct.

    Never thought of that. As you say it works.

    Though you can do this with tables where a different set of values show up depending on the other values in the record. I wonder what Ninox will do?

Content aside

  • 10 hrs agoLast active
  • 31Replies
  • 199Views
  • 6 Following