How to turn an Offer into Invoice (copy record with linked records)


I am trying to solve this issue:

I have table Contracts, Documents and Documents items.

I need to create new Contract (project) and new Document (offer, invoice, etc.) with specific items and prices.

I need to create everything from Table Contracts which is not problem for me.

Now I am looking for a solution how to Copy document with linked items.
Example: Lets say I will create an Offer with ID 1 and I’ll create three items in it - A, B, C and save it. Now how can I simply copy whole Offer with item A, B, C and change it into Invoice easily?

Thank you for your advices.

Hello Thomas,

simple way is to create invoice header and invoice items (two tables) and use workflow automation to create a button in the Offers table (for example: CREATE INVOICE) with javascript model doo.table.

I am sending you an example of one of our application:

const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const isoCurrentDate = `${currentYear}-${(currentDate.getMonth() + 1).toString().padStart(2, '0')}-${currentDate.getDate().toString().padStart(2, '0')}T00:00:00.00Z`;
let dueDate=  new Date( + 14 * 24 * 60 * 60 * 1000).toISOString().substring(0,10);'Info','Creating an invoice');
	let id =; 

const OrdersBySh = await doo.table.getRecord('ordersByShoptet', id);

if ( ===' On-line bank transfer‘) 
	dueDate = isoCurrentDate;
let fields = { 
  invoiceDate: isoCurrentDate,
  ordersByShoptet:{id: id},     
 dueDate: dueDate,
  dateOfTaxableTransaction: isoCurrentDate,
let invoiceHeader= await doo.table.createRecord('issuedInvoices', fields); 

let options =  { filter: '' +id };
const invoiceItems = await doo.table.getData('shoptetrow',options);

const invoicesRow= [];
for (const row of{ 

let fields = {
  invoice: { id: },
  popis: row.fields.itemName, 															
  amount: row.fields.itemAmount,
  unitPraceWithVat: row.fields.itemUnitPriceWithVat,  
  UnitPriceWithoutVat: row.fields.itemUnitPriceWithoutVat,
  vatRate: row.fields.itemVatRate,
  TotalPriceWithVat: row.fields.itemTotalPriceWithVat,
  TotalPriceWithoutVat: row.fields.itemTotalPriceWithoutVat
let invoiceRows=await doo.table.createRecordsBulk('rowsOfIssuedInvoices', rowsOfIssuedInvoices); 

With kind regards,