How manage the behavior of COPY SC standard button (Toolbar)

Dear all,

I’m wondering how can I manage some action when I use the Copy button standard (From toolbar).
In my case for istance when I copy a header of an invoice (master/detail) I would like that new record proposed by pressing copy button would increment
the number of invoce (i.e. Max(InvoiceID) + 1 ) and other fields.
Is it possible or need I to create a custom button ?? I checked within Events but I don’t be sure which use in case.
Thanks

Hi Giovanni

Have you tried to do the same things you do for new record? ( OnLoad, if ( sc_btn_copy or sc_btn_new ) { } )

Ciao Giorgio !!
so I can try to do it in this way… I hope it can work …

if (sc_btn_copy)

{
$sql_def_nr_inv = “SELECT COALESCE( MAX( InvoiceID ) , 0 ) + 1 from invoices”;
sc_lookup(def_nr_inv,$sql_def_nr_inv);
$def_nr_inv = {def_nr_inv[0][0]};

[invoiceNR] = $def_nr_inv;
{InvoiceNumber}= [invoiceNR] ;
[InvoiceID] = {InvoiceID};
[glo_DueDate] = {RequiredDate};
[glo_invoiceDate]={InvoiceDate} ;

}

Yes. And put all under OnLoad event.
Let me know if ok.

Hello Giorgio,
the if test works and now copy the header of invoice correctly.
The steps are following and I got now problem on refreshing the invoice pages.

  1. Find the invoice to copy . OK for istance Nr. 4 the last inserted.
  2. Click on button Copy and now it copy all header infos from invoice 4 and within the invoice nr. field it propose correctly nr. 5
  3. I change for istance the invoice date and eventually other info and then, once ready, I click on Insert/add button
  4. Now my willing is to have the header invoice record saved and the form proposing again invoice nr. 5 just created.

At the moment SC come back to show me, after insert button clicking, the invoice where I started the copy and in this case invoice nr. 4.
and in pages the refreshing is not done. In brief to see the new invoice inserted I need to change page on the bottom using Arrow buttons and then go to first record again . In that moment I can see the new nr. 5 invoce header correctly.

I’ve tried to add a sc_commit_trans(); within event onAfterInsert but still SC re-propose the nr 4.
I can’t insert sc_redir(invoice_form) to reload the form using the ORDER BY invoice number DESC sorting
becouse it need makes some checks and another application . (I ask to user if he likes to update “PrimaNota” table)

I don’t know … what to do, now I’m stucked here… :wink:

Try to check the SELECT in debug mode and see what happens. Maybe yo can change the where using sc_where_add macro