0

JSON in dynamic choice field

Hi,

I was wondering if there's a way to get the value of the 'caption' property of the JSON object used to populate the dynamic choice field?

For instance, you can use the number() function to get the value of the id property.

Thanks a lot.

11 Antworten

null
    • Frank_Bohmer.1
    • vor 1 Monat
    • Gemeldet - anzeigen

    You can use the text(MyChoiceField) function to retrieve the caption of the value.

      • szormpas
      • vor 1 Monat
      • Gemeldet - anzeigen

          Hi Frank, I tried this but it didn't work. Nothing came up in the formula field.

      Another user had the same problem, which you can see here:

      https://forum.ninox.com/t/p8yznz3/json-in-dynamic-fields

      Is this something that's going to be fixed?

      I'd be really grateful if you could clear this up for me.

      • Customer Support Ninox
      • uwe_groegor
      • vor 1 Monat
      • Gemeldet - anzeigen

       This is a bug that is already known and the developers are already working on [ND-9851]

      • szormpas
      • vor 1 Monat
      • Gemeldet - anzeigen

        Hi, many thanks for your reply. I'm waiting on the solution because without it, the new feature isn't really going to be much use.

    • szormpas
    • vor 1 Monat
    • Gemeldet - anzeigen

    Hi,

    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, you could just click a button.

    Is this something we can do right now?

    • UweG
    • vor 1 Monat
    • Gemeldet - anzeigen


     

    This is possible using a text field that contains a JSON as text, which is then parsed in the dynamic selection field.
    Example:
    'TEXTFIELD' = [{"id" : 1, "caption" . "FrankB"},{"id" : 2, "caption" . "UweG"}]

    DynamicChpoice:
    parseJSON(TEXTFIELD)

    However, I currently don't know of a way to address the JSON directly to the dynamic Choice field via script.

      • szormpas
      • vor 1 Monat
      • Gemeldet - anzeigen

        Hi, 

      I don't know why, but for some reason it doesn't work.

      If it's not too much trouble, could you upload a sample database to show us how this feature works?

      Many thanks!

      • szormpas
      • vor 1 Monat
      • Gemeldet - anzeigen

        

      After spending hours trying different things, I've finally found a simple and sustainable solution.

      It seems that parseJSON(TEXTFIELD) alone isn't enough. We need to reconstruct the JSON object:

      for i in parseJSON(Text) do
          {
              id: i.id,
              caption: i.caption
          }
      end

      Can you let me know whether this is a bug or normal behaviour before I make any more changes to my application?

      • UweG
      • vor 1 Monat
      • Gemeldet - anzeigen

       
      Yes, that is the way I currently know of to generate a JSON for a dynamic choice field using a text field.
      The JSON extension for dynamic choice fields was chosen so that you can also specify value assignments using schema changes. If a table is the source of the dynamic choice, you have no influence on the content using schema changes.

    • mirko3
    • vor 1 Monat
    • Gemeldet - anzeigen

    Hi, Sotirios. It is a workaround to get the value of "caption". You can put the JSON as a global function in options and now you can see all values you wont. See the littel DB. Know this is a bit of a complicated JSON construct - you can simplify it as neededMirko

      • szormpas
      • vor 1 Monat
      • Gemeldet - anzeigen

        Hi, great!

      I got the idea. I should build the JSON outside the DC field so I can access it later.

      In my case, it's important that the DC field can accept a JSON object with extra properties other than "id", "caption", "color" and "icon" (like the "value" in your example).