0

Problem accessing a subtable from a reference record

I have a Dynamic Choice field called “Employees”.
In the same table, I also have two numeric fields: “USD” and “ZMW”.
I want to create a button that, when clicked, will find the selected employee in the Employees table and create a new record in that employee’s subtable “Employees_History”, copying the values from the fields “USD” and “ZMW” into the corresponding fields (“Salary USD” or “Salary ZMW”).

let empName := Employees;
let emp := first(select Employees where Name = empName);

if emp != null then
    create emp.Employees_History with {
        'Salary USD': 'USD',
        'Salary ZMW': 'ZMW',
        Date: today()
    }
end


But Ninox does not recognize the command emp.Employees_History.
How can I correctly reference a subtable of the selected employee and create a new record in it?

8 replies

null
    • Fred
    • 10 days ago
    • Reported - view

    Since you are using a dynamic choice field, the record() function is the command that can return the actual record from the table.

    let empRec := record(Employees,number(Employees));
    if empRec != null then
        create empRec.Employees_History with {
            'Salary USD': 'USD',
            'Salary ZMW': 'ZMW',
            Date: today()
        }
    end (empty)
      • iliper LTD
      • iliper_LTD
      • 10 days ago
      • Reported - view

       Thank you for your response, the problem remains.

    • Fred
    • 10 days ago
    • Reported - view

    Yes, silly me. create() only works at the table level.

    let empRec := record(Employees,number(Employees));
    if empRec != null then
        create Employees_History.
            Employees := empRec;
            'Salary USD' := empRec.'USD';
            'Salary ZMW' := empRec.'ZMW';
            Date := today()
    end
      • iliper LTD
      • iliper_LTD
      • 7 days ago
      • Reported - view

      Good morning  
      The formula isn't entirely correct. I'd like to ask you to enter it into the database I sent you earlier and send it. Thank you in advance.

    • John_Halls
    • 7 days ago
    • Reported - view

    The field is called Employees1 so your first line needs to be

    let empRec := record(Employees,number(Employees1));
    

    Regards John

      • iliper LTD
      • iliper_LTD
      • 6 days ago
      • Reported - view

       Thanks 
      Your hint is correct. But the problem with lines 5 and 6 remains. He can't find the fields. I rewrote the first half of the line, indicating the path to the fields, but the second half remains problematic.

    • John_Halls
    • 6 days ago
    • Reported - view

    Hi 

    A couple of things here with lines 5 & 6.

    1. You don't need to state the table name, this will bring up an error.

    2. You don't have the fields 'USD' and 'ZMW' in the Employees table. From what I can see they are in the Expenses_Table table.

    3. You don't have a Date field, there are 'Beg Date' and 'End Date'

    4. If you use create Employees_History directly the fields being updated then need to be wrapped in brackets.

    I have keyed this into your button without any errors, so I am hoping it will work for you

    let thisRec :=this;
    let empRec := record(Employees,number(Employees1));
    if empRec != null then
        create Employees_History.(
            Employees := empRec;
            'Sallary USD' := thisRec.'USD';
            'Sallary ZMW' := thisRec.'ZMW';
            'Beg Date' := today());
    end
    

    Regards John

      • iliper LTD
      • iliper_LTD
      • 6 days ago
      • Reported - view

       Thank you very much, everything works correctly.

Content aside

  • Status Answered
  • 6 days agoLast active
  • 8Replies
  • 50Views
  • 3 Following