0

Warning on button coding: "Field must return dynamic values..."

Hi there!

After some trial and error, I came out with this coding that works as expected but I can't get rid of the warning sign saying: Field must return dynamic values...

 I'm generating a new record from table Asiento to a different table (Gastos) where there are two dynamic choice fields working in cascade (depending on the selection of supplier "Proveedor" and pointing to table "Servicios Contratados") . This is my coding (I simplified it leaving the issue in question only):

let asiento := this;
let gasto := (create Gastos);
gasto.('Fecha Doc.' := asiento.'Fecha Asiento');
gasto.('Nro. Factura' := "S/Justificante");
gasto.(Proveedor := 34);
gasto.('Categoría' := first(select 'Servicios Contratados' where Proveedores = 34));
gasto.('Subcat.' := first(select 'Servicios Contratados' where Proveedores = 34));
let servicio := (create Servicios);
servicio.(Concepto := asiento.Movimiento);
servicio.('Base Imponible' := asiento.Importe * -1);
servicio.(Gastos := gasto)

The thing that troubles me is that it works as expected:

 So, I'm totally lost on why it works the first time and just after it gives me this error/warning.

I've also tried with record(... function but it doesn't select the values.

Thanks for any help on this!

5 replies

null
    • Fred
    • 2 mths ago
    • Reported - view

    can you post a sample DB, one without personal data?

      • Marisol_Echaide
      • 2 mths ago
      • Reported - view

      Sure! I've emptied manually leaving only some info in the tables related to the issue. It seems something's going on with the dropdown menu on the MacOs app.

      To replicate the behaviour:

      1. From the table Asientos (any existing record) hit the button "Gasto Sin Justificante".

      2. The new record is created in the table "Gastos". The fields in question (DC) are "Categoría" and "Sub categoría".

      Fun fact 😅: if you edit the coding in the button "Gasto Sin Justificate" (say, cut and paste the coding, add any coding line, etc.), then, without Saving Changes, you hit the button...it works! But after that action or if you save changes, you get the error message. (I left a created record in Gastos table as evidence).

    • Fred
    • 2 mths ago
    • Reported - view

    You can change first to number and it should work.

    gasto.('Categoría' := number(select 'Servicios Contratados' where Proveedores = 34));
    

    When you do a select you get back table id and record id. So then we have to convert the nid info into plain numbers. It looks like Ninox doesn't like table/record data being passed to make a selection of a dynamic field. I thought you could, but this error message shows otherwise.

    On a side note, when referencing new record variables you can simplify the code by doing:

    gasto.(
        'Fecha Doc.' := asiento.'Fecha Asiento';
        'Nro. Factura' := "S/Justificante";
        Proveedor := 34;
        'Categoría' := number(select 'Servicios Contratados' where Proveedores = 34);
        'Subcat.' := number(select 'Servicios Contratados' where Proveedores = 34)
    );
    

    This method also can be done when creating json.

      • Marisol_Echaide
      • 2 mths ago
      • Reported - view

      you're awesome! Thanks!

      I've updated my coding based on both your suggestion and your invaluable insights. The only thing I noticed is that the new record still had unselected options in the DC fields.

      Just to experiment, I added this syntax:

      number(first(select 'Servicios Contratados' where Proveedores = 34))

      and now the new record shows both DC fields with the right selection (yei!). So far, it seems there's been no warning or error message (fingers crossed when I Save Changes 😅).

      Again, thanks a million for your help!

      • Fred
      • 2 mths ago
      • Reported - view

      I didn't test out the code without the first() command. Ninox doesn't give an error when you don't have the first() command but then an array is passed to the dynamic choice field and Ninox can't assign an array to a single choice. So you do need the first() command, like you figured out.

Content aside

  • Status Answered
  • 2 mths agoLast active
  • 5Replies
  • 78Views
  • 2 Following