0

Add/Insert record on button click

Hello,

I am trying to create a new record on button click, however it is not able to find the specified column in the target table. Am I missing something?

Attached are the screenshots of two tables (Accounts Receivables and Orders)

I don't understand why is this happening, but I am not able to create record in the AccountReceivables table for recording a payment received for an Order.

6 replies

null
    • Fred
    • 4 mths ago
    • Reported - view

    i’ve found that “this” really only works when in a variable. There are moments that it works inside code but it is too inconsistent to try to remember when. 

    So put add a new line 1 with:

    let t := this;

    then use t and it will work. 

      • Database App Developer
      • vermau81
      • 4 mths ago
      • Reported - view

       Thank you mate. It worked like charm. Just one little problem and one clarification.

      Clarification: What does this signify here? does it refer to the whole table in context or the current record in that table (Orders table)?

      Problem: There is a reference to the Customers table in both the tables (Account Receivables and Orders). I am trying to copy the First and Last name of the customer in the new record being created in AccountReceivables from the Orders table, but it does not get copied.

      let t := this;
      let newReceipt := (create 'Account Receivables');
      newReceipt.('Order Number' := t.'Order Number');
      newReceipt.('Receipt Date' := today());
      newReceipt.('Receipt Amount' := t.'Pmt Received');
      newReceipt.('Mode of Receiving' := t.'Mode of Payment');
      newReceipt.Customer.('First Name' := t.Customer.'First Name');
      newReceipt.Customer.('Last Name' := t.Customer.'Last Name')
      

      Is my code ending complete or is there anything that I need to add in the end like save or commit in SQL?

    • Fred
    • 4 mths ago
    • Reported - view
     said:
    Clarification: What does this signify here? does it refer to the whole table in context or the current record in that table (Orders table)?

     "this" points to the current record.

     

     said:
    Problem: There is a reference to the Customers table in both the tables (Account Receivables and Orders). I am trying to copy the First and Last name of the customer in the new record being created in AccountReceivables from the Orders table, but it does not get copied.

     I see you made a new record in Account Receivables, but I don't see you making a link to a Customer record. Once you do that then you don't need to copy anything as it will link to the same record.

    I'm guessing you want to link to the same Customer that is in the Orders record. If that is true, paste the code update that shows setting Customer in Account Receivables to Customer in Orders.

      • Database App Developer
      • vermau81
      • 4 mths ago
      • Reported - view

       please excuse my little knowledge considering I am still a starter in Ninox.

      customers is linked to both AccountReceivables and Orders tables separately, so doesn’t that mean that there is an inherent relation between all three tables. Why do I need to link the same customer that is in Orders record.

      I just want to copy the same customer name in the new record so that when we see a report from AccountReceivables in the Table view (eg: records of all those customers who paid money in the month of Jun 24) it will display the customer name in the records.

      Can you help me with syntax how to refer to FirstName in Customers table from within AccountsReceivables table. Is the below syntax not correct?

      newReceipt.Customers.(‘First Name’) := t.Customers.(‘First Name’)

    • Fred
    • 4 mths ago
    • Reported - view
     said:
    customers is linked to both AccountReceivables and Orders tables separately, so doesn’t that mean that there is an inherent relation between all three tables. Why do I need to link the same customer that is in Orders record.

    You have to make those links when you create a new record.

    When you use the create command it like going to the Account Receivables table and creating a new record. When you do that is the customer reference field linked to anything? It is not, you have to tell it what record in customer you want to link it to.

    So you have to explicitly state how the customer field needs to be linked when you create the new record.

    let t := this;
    let newReceipt := (create 'Account Receivables');
    newReceipt.(
        'Order Number' := t.'Order Number';
        'Receipt Date' := today();
        'Receipt Amount' := t.'Pmt Received';
        'Mode of Receiving' := t.'Mode of Payment';
        Customer := t.Customer;
    );
    
    • Database App Developer
    • vermau81
    • 4 mths ago
    • Reported - view

    Awesome, I could not remember that just like even though Customer is a reference field in the Orders or AccountReceivables form, we still have to select the customer from the Customers table, same way we have to select the customer here as well in the code.

    Thank you dear. There is a lot of learning from me to take and with nice people like you and others it will become an easy journey for me.

    Regards,

Content aside

  • Status Answered
  • 4 mths agoLast active
  • 6Replies
  • 92Views
  • 2 Following