Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Duplicating an Invoice


This topic is 6546 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted (edited)

I have an Invoice layout (invoice table) with portal rows(invoice data table) of invoice line items. Would like to be able to duplicate the invoice and have the line itmes in the portal be duplicated as well. This would create a new invoice with the serial number incremented by one and the portal data duplicated with the new serial number.

End result would be: two invoices with identical data but different invoice numbers.

Edited by Guest
Posted

Hi Chris and welcome to the forums

Lord only knows why you want this to happen (sounds like an administrators nightmare) but what you can do is script to print the invoice twice and in between the print instructions use a set field instruction to set the invoice number to invoice number + one

HTH

Phil

Posted

Chris:

I think Phil misunderstood you. You want to actually create a second invoice, identical to the first invoice. This can be a bit involved, because you need to duplicate related information, and make sure it is connected correctly together. You will have to write a script which will do the following (the key fields for the relationship being Invoice::yourkeyfield and LineItem::foreignkeyfield):)

1. Duplicate the invoice itself. Go to a layout which displays data for the invoice table, isolate it, and duplicate it:

Enter Browse Mode

Go To Layout [invoicelayout]

Show All Records

Omit Record

Show Omitted Records

Duplicate Record/Request

2. Now you're on the duplicate invoice. Your key field (for the portal relationship) should have incremented itself automatically. Change any other info you need to change here, via Set Field[] steps. Copy the key field by setting a variable. We do this for a number of reasons.

Set Variable [$keyfield; yourkeyfield]

3. Now comes the tricky part. Go back to the original invoice, set a variable, then find the related items (the portal items) so you can duplicate them. To do this you'll have to go to a layout showing records from the related table directly (not in a portal).

Go to Record/Request/Page [previous] // goes to original invoice

Set Variable [$findfield; yourkeyfield]

Go to Layout [portalitems]

Enter Find Mode

Set Field [foreignkeyfield; $findfield]

Perform Find

4. Now you've found the related records, in their native environment. You'll want to duplicate them, too.

Go To Record/Request/Page [first]

Loop

Duplicate Record/Request // also puts you on the duplicate

Set Field [foreignkeyfield; $keyfield]

Omit Record // gets rid of the duplicate from the found set

Go To Record/Request/Page [first]

Omit Record // gets rid of the original from the found set

Exit Loop If [Get(FoundCount)=0]

End Loop

5. Now you should have your records duplicated, so we go to the main layout and find the new invoice.

Go To Layout [yourinvoicelayout]

Enter Find Mode

Set Field [yourkeyfield; $keyfield]

Perform Find

I'm typing that freehand, and haven't tested it, so that might not precisely work, but that's the method I use. You would want to add some error correction, etc. to this. Essentially, you find the invoice, duplicate it, store the key fields for the original and the duplicate, find the original's line-items, then loop through duplicating them and setting the duplicate's foreign key to the correct value.

Good luck

-Stanley

  • 2 weeks later...
Posted

Your solution worked great. Thanks for taking the time to help me with this vexing problem. I'am in your debt!

This topic is 6546 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.