Copy record data from a table and create a record in other table
I need your help in creating a code for a button that allows me to copy and paste the data of a record from one table to another.
I have a table 'ORDERS A' and a table with 'ORDERS B'.
The problem is that 'ORDERS B' has an internal table linked to 'CLIENTS' and I cannot copy the customer name contained in the table 'ORDERS A' into the table 'CLIENTS' linked to 'ORDERS B'.
I tried the following code (from the 'ORDERS A' table) but there must be some error:
let a: = 'PROD ID';
let b: = 'ORDER DATE';
let c: = 'AGENT';
let x: = (create 'ORDERS B');
x. ('ID ORD': = a);
x. ('Order Date': = b);
x. ('CLIENTS.AGENT': = c);
Thanks in advance for your suggests
9 replies
-
Hi there -
Maybe this will work:
1) you need to create a variable to your current record:
let curRec := this;
2) then you can simplify the next section to:
let x := (create 'ORDERS B');
x.('ID ORD' := curRec.'PROD ID');
x.('ORDER DATE' := curRec.'ORDERDATE');
x.('CLIENTS' := curRec.AGENT); <--this is the important part, assuming that AGENT is the name of the reference field in Orders A and CLIENTS is the name of the reference field in ORDERS B. If it is not then make sure to put the exact name of the reference field from Orders A and B in their respective places. There are many discussions on these forums about best practices on naming of reference fields. For me I like to make them the same so I know what Table I'm pointing to, but others make good points about naming them differently so you don't get confused.
It took me awhile to get use to the idea that linking reference fields the only thing you need is the name of the reference field and Ninox will do the linking for you if they are the referencing the same table. You don't need to point it to the field ID or anything else.
Hope this helps.
-
first problem -
-
If you delete 'ID PROD', then start typing id what fields does it offer you? if it offers you ID PROD does it work then?
-
I understood the problem!
ID PROD is a field of the other table (PRODUCTS)! ...linked to ORDERS table -
Also, since SUB - USERS is a reference field, you only need to do:
x.('SUB - USERS' := curRec.'SUB - USERS')
Then this will create the proper link in the ORDERS table. From there you can then show whatever field you want, i.e. Sub user name.
-
Thanks Fred for your support...but I don't solve the problem yet!
I try to explain better...I hope ;-)!
This is my APP:
I have to create a code to take the 'ORDERS IMPORT' record and create a new record in 'ORDERS' table.
'ORDERS IMPORT' table fields:
- 'Order Number Import' (number field)
- 'ID Prod Import' (number field)
- 'Sub Agent Name' (field from 'SUB' table)So...
- the 'Order Number Import' field has to go in the new record 'Order Number' field in the 'ORDERS' table
- the 'ID Prod Import' field has to take the right 'ID Prod' field in the 'PRODUCTS'
- the 'Sub Agent Name' field has to associate the right 'Sub Agent Name' in the 'SUB'
No easy to explain...Even more complex (for me) the code :-) -
When I try to troubleshoot my code, I try to strip it down to just one function so I can debug it easier. How about trying this simple code in your button:
let curRec := this;
let newRecord := (create ORDERS)
newRecord.('Sub Agent Name:= curRec.'Sub Agent Name')<--assuming Sub Agent Name is the the exact name of the reference field in your ORDERS and ORDERS IMPORT tables. If not then make sure they match the field name in the ORDERS and ORDERS IMPORT table not the SUBS table.
Does it create the record with the proper link to the SUBS table? If so then you can edit the formula to start copying more and more data. You can then add:
newRecord.(Order Number := curRec.'Order Number Import');
etc, etc.
-
OK
So far ... it works
Create a new order and correctly associate the Sub Agent name
let curRec := this;
let newRecord := (create ORDERS);
newRecord.('Agent or Sub-Agent' := curRec.'Agent or Sub-Agent');
newRecord.('Sub - Agent Name' := curRec.'SUB - USERS');
newRecord.('Order AMZ Number' := curRec.'Order AMZ Number');
newRecord.('Order Date' := curRec.'ORDER DATE');
newRecord.('Profile AMZ Link' := curRec.'Profile AMZ Link');
newRecord.('Profile Short Link' := curRec.'Profile AMZ Link')
Now I have to use the 'ID Prod Import' field to insert it in the correct Prod ID field of the ORDERS table, remember that the PRODUCTS table is linked to that of the ORDERS ... while the 'ID Prod Import' field (of the ORDERS IMPORT table ) is simply a numeric field
Content aside
- 3 yrs agoLast active
- 9Replies
- 1254Views