AnsweredAssumed Answered

Save Records as PDF scripting issue saving pdf to all records in table

Question asked by user2148443 on Nov 15, 2018
Latest reply on Nov 16, 2018 by user2148443

I have an issue with saving to a PDF. Original script i just kept the pdf in one place, however, the issue was if i overwrite that pdf with a new version i lost the previous/original pdf.

Original Script

 

 

#

#

# Prepare the record

Freeze Window

Allow User Abort [ Off ]

Go to Related Record [ Show only related records ; From table: “TO_01____CUSTOMERS” ; Using layout: “L100 QouteLayout” (TO_01____CUSTOMERS) ; New window ]

If [ Get ( LastError ) ≠ 0 ]

Halt Script

End If

#

Show All Records

Omit Record

Show Omitted Only

#

Enter Preview Mode [ Pause: Off ]

#

# Prepare the pdf

Set Variable [ $PATH ; Value: Get ( TemporaryPath ) & TO_01____CUSTOMERS::SiteAddressShort &"_" & Substitute ( Get ( CurrentDate ) ; "/" ; "-" )&  ".pdf" ]

Save Records as PDF [ Restore ; With dialog: Off ; “$PATH” ; Records being browsed ; Create directories: Off ]

#

#

# Exit Script

Close Window [ Current Window ]

Insert File [ TO_01____CUSTOMERS::Quotation PDF ; “$PATH” ]

#

Commit Records/Requests [ With dialog: On ]

Beep

#

 

I had created a second table to store each copy of the PDF i created. and create a script to get it to save there and created a new script to do this. It also checks to see if there is an old pdf and if so replaces with the new one.

 

#

#

# Prepare the record

Freeze Window

Allow User Abort [ Off ]

Set Variable [ $CUSTOMERID ; Value: TO_01____CUSTOMERS::CUSTOMER ID MATCH FIELD ]

Set Variable [ $Date ; Value: Get(CurrentDate) ]

Go to Related Record [ Show only related records ; From table: “TO_01____CUSTOMERS” ; Using layout: “L100 QouteLayout” (TO_01____CUSTOMERS) ; New window ]

If [ Get ( LastError ) ≠ 0 ]

Halt Script

End If

#

Show All Records

Omit Record

Show Omitted Only

#

Enter Preview Mode [ Pause: Off ]

#

# Prepare the pdf

#

Set Variable [ $PATH ; Value: Get ( TemporaryPath ) & TO_01____CUSTOMERS::SiteAddressShort &"_" & Substitute ( Get ( CurrentDate) ; "/" ; "-" )&  ".pdf" ]

Save Records as PDF [ Restore ; With dialog: Off ; “$PATH” ; Records being browsed ; Create directories: Off ]

#

# Exit Script

Close Window [ Current Window ]

#

# Save to Related Documents Table

#

New Window [ Style: Card ; Name: "Saving Qoutation" ; Using layout: “TO_13____PROPERTY_RELATED_DOCUMENTS” (TO_13____PROPERTY_RELATED_DOCUMENTS) ]

New Record/Request

Set Field [ TO_13____PROPERTY_RELATED_DOCUMENTS::CUSTOMER_ID_MATCH ; $CUSTOMERID ]

Set Field [ TO_13____PROPERTY_RELATED_DOCUMENTS::DATE ; $Date ]

Set Field [ TO_13____PROPERTY_RELATED_DOCUMENTS::DOCUMENT_NAME ; TO_01____CUSTOMERS::SiteAddressShort &"_" & Substitute ( Get ( CurrentDate ) ; "/" ; "-" )&  ".pdf" ]

Insert File [ TO_13____PROPERTY_RELATED_DOCUMENTS::DOCUMENT ; “$PATH” ]

Commit Records/Requests [ With dialog: On ]

#

Close Window [ Current Window ]

#

# Save to Orginal Location

#

If [  not IsEmpty ( TO_01____CUSTOMERS::Quotation PDF ) ]

Replace Field Contents [ With dialog: Off ; TO_01____CUSTOMERS::Quotation PDF ; $PATH ]

End If

Insert File [ TO_01____CUSTOMERS::Quotation PDF ; “$PATH” ]

#

Commit Records/Requests [ With dialog: On ]

Beep

#

 

I thought it was working fine but just discovered it is saving to both locations as it is meant to but, it is also updating every record in the table, not just the current/related record.

Outcomes