Copy record to another table

Hello,

I have identical offers and orders tables. in the offer form I have a button Copy to order.
How do I write a script to copy the selected offer record to the orders table?

Thank you for advice.

Hi,
try this script:

//name of destination table
const destinationTable = 'orders';

//create new object (IDooApiTableOrders - use your tableName and your field names)
let field = <IDooApiTableOrders>{};
field.code = doo.model.code.value;
field.date = doo.model.date.value;
field.email = doo.model.email.value;
field.status = doo.model.statusName.value;

//create new record
const newRecord = await doo.table.createRecord(destinationTable, field);

Thank you for your answer.

Hello, can you please still advise me how to connect the copied offer to the supplier. Thank you

You can use

field.supplier = {doo.model.supplier.id}

Pavel thank you for your advice,
I am a beginner in javascript. Your advice in the context of the previous script reports an error
Type { doo …} is no assingnable to type 'IDooApiLinkToOne<IDooApiTable…>.

Can you please write an entire script, under the CopyChild button, that creates a copy of the Child record and links it to the parent it was copied from.

Thanks
Jan

Do you want to do it in that given code?

Pavle please write it from scratch for the following example.
The Invoice table (Number, Date, Amount, Description) is linked to the Supplier table (Name, Address). Make a copy of the Invoice record, increase the invoice number by 1 and link the record to the given Vendor.
Thank you

Sorry, I dont fully undestand what you want to do.

Please describe the whole.

What I get:

Offer:

  • fields

Copy to order:
*fields

To link a supplier you need to input the id of supplier, see API doc. Where do you take the supplier from? In last post you added the invoice. Maybe contact me by PM, we can take a look at that.