0

Dynamic Choice from Dynamic Multi Choice

I have a Multi Choice Dynamic field with which multiple choices can be selected (obviously). I then want to have a Dynamic Choice field, based on that same table but that includes ONLY those choices ('records') from the DMC field.

The DC can be built by using a 'contains(…)'  in the Where clause, but this is text only and although it can be made to work with Ids, it's a bit cumbersome.

I have the list of Ids that I want, but how is the best way to select from a table, only those records with the known Ids (i.e. from the original DMC field)?

Also, how can one 'copy' a D(M)C field?

So if such a field exists (populated as desired), how can exactly the same field be used in another location? Obviously the same selection criteria could be used to build the second field, but if that is changed in either, it has to be replicated to the other field.

Is there a way to simply replicate such a field so only one actual calculation is done, from which the 2 fields are created?

9 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    The first part of your question can be solved with something like this in the formula part of the dChoice field:

    let prevDMC := numbers(dMC);
    (select Table1)[(var a := this;
            count(prevDMC[= a])) > 0]
    

    You would of course change:

    dMC to match your dynamic multi choice field name

    Table1 to match the table name from the dMultiChoice.

    The thing to be aware is that under Show As, Radio buttons are not automatically updated as the dMultiChoice field is modified. Combobox and Switch are. Weird bug that Ninox is aware of.

    The 2nd part I'm not sure what you are asking.

    So if such a field exists (populated as desired), how can exactly the same field be used in another location?

    What is another location? Another table? Another record?

    • UKenGB
    • 1 yr ago
    • Reported - view

    That first part of the answer looks interesting, not a construct I have come across before. I'll need to have a play around with that.

    Regarding the second part of my question:-

    If I have a table and use that to build a D(M)C field in a particular table, but then want another 'choice' field (so different name) with the same options either elsewhere in that same table (e.g. a different tab) or even in another table, is it possible to create a duplicate? A regular field's data can be duplicated by using a Formula field, but doing that for a D(M)C field just gets you the IDs of what has been chosen (or text if you want that), but I was looking for a way to end up with another D(M)C field with the same list of options as the first D(M)C field.

    I can create the same 'construction' formula to get the same options, but if for any reason those change, I have to update each one of these D(M)C fields to keep them the same.

    It did occur to me that if I could use a global function to create the choices list, then simply use that same function for each of these D(M)C fields that need to be the same, then that would provide the 'single source' for each of these fields. But I'm not sure if that would be possible as I've not had a chance to check so need to do that. However, is there any way to achieve this?

    • Fred
    • 1 yr ago
    • Reported - view

    Playing around it looks like they have made dynamic multichoice fields a bit easier to update by code. If you create a formula field and put the following code in:

    raw(dMultiChoice1)

    You will see a hex decimal number that changes as you change the selection in your dMultiChoice field.

    I then decided to try in the Trigger after Update of dMultiChoice1:

    let xraw := raw(dMultiChoice1);
    dMultiChoice2 := xraw
    

    Of course with the background that dMultiChoice2 points to the exact same table as dMultiChoice1. I guess you don't have to point it at the same table but then the selections would be unrelated.

    Anyways, low and behold it works. As I change dMultiChoice1, dMultiChoice2 is updated. Hey, even as radio buttons now. I'm now running MacOS v3.6.8 and it looks like they have fixed the radio button issue.

    Then I tried out modifying a dMC in another table with:

    let xraw := raw(dMultiChoice1);
    dMultiChoice2 := xraw;
    Table1.(dMC1 := xraw)
    

    And that works too. I'm using an existing reference field (called Table1). If there is no relationship between the tables then you will need to do a select.

      • UKenGB
      • 1 yr ago
      • Reported - view

      Fred Interesting, but I want to simply duplicate the options available (i.e. only some records from the source table) rather than the selection state.

      To perhaps explain better:-

      I have a table of Units (of measure, so pounds, ounces, grams, kilograms etc). The first DMC field is built from that table, the user selects which units to use and a DC field is then created, containing only those selected choices from the DMC field and in that case the user chooses the exact unit to use (to correspond with entered data).

      For this, the topic you pointed to will be extremely valuable for simplifying the creation of the DC field from choices made in the DMC field.

      However, that DC field then needs to be used in multiple places, in which different choices may be made. So it requires duplicating the selection of records that will comprise the DC options, but allowing each to have independent selection of which unit to use.

      I figured that being able to 'copy' a DC field in this way would be more efficient than having to build the list for each one.

      • Fred
      • 1 yr ago
      • Reported - view

      If you want each of the DC fields to be independent of each other then you would need copy the Dynamic Value code to each field.

    • UKenGB
    • 1 yr ago
    • Reported - view
    Fred said:
    this post

     That was fascinating, but I'll need to go over it a few times. For the last few months I've been using what I had previously created with Ninox and missed some new changes.

    • UKenGB
    • 1 yr ago
    • Reported - view

    I've figured out how to 'duplicate' the options list from one DMC to another.

    Create the selection criteria in a (hidden) formula field. Then enter that formula field as the 'Dynamic values' of the DMC field. This works and the same list of options can then be used multiple times, but only calculated and built once. Also the code only exists in one place, making maintenance easier.

      • Fred
      • 1 yr ago
      • Reported - view

      That is great. If you are comfortable, please share the code so we can all learn from your successes.

Content aside

  • 1 yr agoLast active
  • 9Replies
  • 393Views
  • 3 Following