How do I set up a new Destination to print to PDF to a specified path and a specified file name?

SUGGESTED

I would like to print Sales Invoices to a specific network file share and name it Business Partner number + Invoice Number + Date.PDF.  Is there a way to do this NON-custom?  I'm looking in All...  Setup... Destinations.

  • 0
    SUGGESTED

    No it's custom.  I've done this mod and the file name has customer ID, Invoice, Customer PO and source SO all fileds fixed length zero filled and saved as a pdf.   

    The hardest part was creating the file.  I'm forgetting now but we printed to a location and then grabbed the file and renamed it.   If there was any delay the thing failed and we got nothing or a blank report or weird stuff.  I think we finally put a delay loop in or something.  As far as I know it's been reliable for over a year.

    Let me know if you want it and we can make arrangements offline.      

  • 0

    I did a customization that adds buttons for Create/View/Delete PDF to a screen with a script that saves the file and attaches to the Sage record. After we update to Patch 24 I'll have to see if it still works the same - Sage has been gradually removing classic functions from the runtime.

  • 0 in reply to EricButter

    Hey Eric, 

    I would love to see the customization for this. Mind sharing? 

  • 0 in reply to Zach Porter

    Here is the Specific Script for a solution I created.

    You will need to setup your environment and alter the script in order to have a functioning solution - it's designed for the Sales Bill of Lading (GESBOLS) window, header screen, and report. You also need to create an X3 storage area in which to place the PDF that will be attached to the BOL record.

    This was last tested on V12 P18.

    ############################


    Local Char BOL (30) #BOL number
    Local Char WEIGHTUNIT (5) #Weight unit for report
    Local Char FILFOLDER (100) #The server folder for BOLs
    Local Char ATTFOLDER (100) #The attachment folder for BOLs (corresponding to FILFOLDER)
    Local Char FILPTH (100) #The full server file path
    Local Char ATTPTH (100) #The full attachment path
    Local Char BOLPDF (30) #The filename of the PDF
    Local Integer BOLYR (4) #The BOL year
    Local Integer OKYES #Success flag
    Local Char CURRENTOP (10) #Operation being attempted

    $ACTION
    Case ACTION
    When "AVANTBOUT" : Gosub AVANTBOUT #After button/menu is clicked
    When "FICHIER" : Gosub FICHIER #When the report is run and the filename is set
    When "OUVRE" : If clalev ([RPT]) : Gosub OUVRE : Endif #When the report opens
    When "SETBOUT" : Gosub SETBOUT #Enable/disable options before redraw
    Endcase
    Return

    ############################

    $AVANTBOUT # A button was pressed
    Local Integer OLDTIMOUT
    OLDTIMOUT = GTIMOUT
    Case BOUT
    When "5" : CURRENTOP = "Create" : Gosub SAVBOL : Gosub STATUSMSG #Create BOL file and attach to the record.
    When "6" : CURRENTOP = "Replace" : Gosub SAVBOL : Gosub STATUSMSG #Replace BOL file and reattach it to the record.
    When "7" : CURRENTOP = "Clear" : Gosub CLRBOL : Gosub STATUSMSG #Remove BOL file and attachment from the record.
    When "8" : CURRENTOP = "Open" : Gosub OPNPDF #Open the PDF attachment. Don't show a status message.
    Endcase
    GTIMOUT = OLDTIMOUT
    Gosub RELIT From GOBJSUB #Refresh the window to update the attachment icon.
    Return

    ############################

    $SETBOUT #Determine conditions for enabling/disabling buttons/menus.
    Gosub SETPRM
    # Check if there is an attachment record for this BOL.
    If !clalev([AOX]) : Local File AOBJTXT : Endif
    Filter[AOX] Where ABREV = 'BOL' and IDENT1 = BOL
    If rowcount([AOX])
    # The attachment record exists. Enable Open and, if Admin user, enable Replace and Clear.
    CHMEN += "Y8" #Open
    If GUSER = 'ADMIN'
    CHMEN += "Y6" #Replace
    CHMEN += "Y7" #Clear
    Endif
    Else
    # The attachment record does not exist. Check if there is a detail record for the BOL
    # and if so, enable the Create button.
    If !clalev([BOLD]) : Local File BILLLADD : Endif
    Filter[BOLD] Where BOLNUM = [M:BOL0]BOLNUM
    If rowcount([BOLD]) : CHMEN += "Y5" : Endif #Create
    Endif
    Filter[BOLD] : Filter[AOX]
    Return

    ############################

    $SAVBOL #Write the BOL report to a PDF. Attach the PDF to the BOL record.
    Gosub SETPRM
    #Check if the folder exists.
    Gosub CHKFOLDER: If !OKYES : Return : Endif
    #Check if file can be deleted.
    Gosub CHKOVRWRT: If !OKYES : Return : Endif
    #Delete the file.
    Gosub DELFIL : If !OKYES : Return : Endif
    #Save the file.
    Gosub SAVFIL : If !OKYES : Return : Endif
    #Attach the file.
    Gosub ATTBOL
    Return

    ############################

    $ATTBOL #Attach the PDF link to the BOL record.
    Gosub SETPRM
    GTIMOUT = 10
    OKYES = 0
    While !OKYES
    If !clalev([AOX]) : Local File AOBJTXT [AOX] : Endif
    [F:AOX]ABREV = "BOL"
    [F:AOX]IDENT1 = BOL
    [F:AOX]IDENT2 = BOLPDF
    [F:AOX]IDENT3 = GUSER
    [F:AOX]MOTCLE(0) = BOL
    [F:AOX]MOTCLE(1) = GUSER
    [F:AOX]IDENT3 = "001"
    [F:AOX]NAM = ATTPTH
    [F:AOX]TYPDOC = "PDF"
    Trbegin [AOX]
    Write [AOX]
    Case fstat
    When 0 : Commit : OKYES = 1
    When 1 : Call ERREURT ("\Attachment table is locked.", 1) From GESECRAN : Rollback : OKYES = 0 : Return
    When 3 : Rollback : Gosub DELATT : If !OKYES : Return : Else : OKYES = 0 : Endif #Record exists, rollback, delete, reset and try again
    When Default : Call ERREURT ("\fstat error" - fstat + ".",1) From GESECRAN : Rollback : OKYES = 0 : Return
    Endcase
    Wend
    Return

    ############################

    $CLRBOL #Delete the PDF document and the Attachment record.
    Gosub SETPRM
    GTIMOUT = 30
    Local Integer OKCAN : OKCAN = 1
    Call AVERTIRT("\Are you sure you want to delete" - BOLPDF - "and clear it from" - BOL + "?", OKCAN) From GESECRAN #OKCAN = 1 if OK is pressed.
    If OKCAN = 1 : OKYES = 0 : Return : Endif
    #Delete the PDF document
    Gosub DELFIL : If !OKYES Then Return : Endif
    #Delete the Attachment record
    Gosub DELATT
    Return

    $OPNPDF #Open the PDF from the attachment on the BOL
    Gosub SETPRM
    #Replace the ATTPTH with the attachment record's value (don't rely on SETPRM value)
    If !clalev([AOX]) : Local File AOBJTXT : Endif #Open the attachments file if not already open.
    For [AOX] Where ABREV = 'BOL' and IDENT1 = BOL #'Loop' over the one record
    ATTPTH = [AOX]NAM
    Next
    #Call MESSAGE(ATTPTH) From GESECRAN : Return
    Local Char PARMSK(250)(1..20) , SAVACT(20)
    SAVACT = GACTION : GACTION = "ASYRVISU"
    PARMSK(1) = ATTPTH
    VALEUR = ATTPTH
    Call TRAITE_CHAR(VALEUR,PARMSK,"","ASYRVISU","",1,"") From GTRAITE
    GACTION = SAVACT
    Return

    ############################

    $STATUSMSG #Based on ending value of OKYES, show an appropriate status message.
    If !OKYES : CURRENTOP += " not " : Endif
    CURRENTOP += " completed on" - BOL + " : document" - BOLPDF - "."
    GTIMOUT = 5
    OKYES = !OKYES #The message box needs a 1 for error, 0 for normal.
    Call ERREURT("\" + CURRENTOP, OKYES) From GESECRAN
    Return

    ############################

    $SETPRM #Set common parameters.
    BOL = [M:BOL0]BOLNUM
    WEIGHTUNIT = [M:BOL1]WEU(0)
    BOLPDF = BOL + ".pdf"
    BOLYR = year([M:BOL0]BOLDAT)
    FILFOLDER = filpath("","","") + "\ATT\CUSBOL\" + num$(BOLYR) + "\"
    ATTFOLDER = "[CUSBOL]/" + num$(BOLYR) + "/"
    FILPTH = FILFOLDER + BOLPDF
    ATTPTH = ATTFOLDER + BOLPDF
    Return

    ############################

    # The following are utilities for use with the main actions:

    $CHKFOLDER
    Case filinfo(FILFOLDER,7)
    When 0 : OKYES = 1 : Return #folder exists
    When -27 : OKYES = 0 : GTIMOUT = 10 : Call ERREURT ("\Access denied on folder" - FILFOLDER + ".",1) From GESECRAN : Return
    When -20 #Folder/year doesn't exist
    Call ERREURT("\Required folder" - FILFOLDER - "was not found on the Sage app server. Please add folder" - num$(BOLYR) + "." , 1) From GESECRAN
    OKYES = 0 : Return
    When Default:
    Endcase
    Return

    $CHKOVRWRT #See if the file may be overwritten if it exists.
    OKYES = 1 #Yes if file doesn't exist.
    Local Integer OKCAN : OKCAN = 1
    If filinfo(FILPTH,7) > 0
    GTIMOUT = 30
    Call AVERTIRT("\Are you sure you want to overwrite existing document" - BOLPDF + "?", OKCAN) From GESECRAN #OKCAN = 1 if cancel is pressed.
    If OKCAN = 1 : OKYES = 0 : Endif
    Endif
    Return

    $DELFIL
    OKYES = Delfile(FILPTH)
    If OKYES = -27 : GTIMOUT = 10 : Call ERREURT ("\Access denied deleting document" - BOLPDF + ".", 1) From GESECRAN : OKYES = 0 : Return : Endif
    OKYES = 1
    Return

    $SAVFIL
    #Parameters for report ZXJB3BOL.
    Local Char TBPAR(150)(1..3),TBVAL(150)(1..3)
    TBPAR(1) = "bol" : TBVAL(1) = BOL
    TBPAR(2) = "weightunit" : TBVAL(2) = WEIGHTUNIT
    # Run the report without the info message (0).
    Call ETAT("ZXJB3BOL","BOL","",0,"",TBPAR,TBVAL) From AIMP3
    OKYES = 1
    Return

    $DELATT #Delete Attachment record from the BOL record.
    If !clalev([AOX]) : Local File AOBJTXT [AOX] : Endif
    Trbegin [AOX]
    Delete[AOX] Where NAM = ATTPTH and ABREV = 'BOL' and IDENT1 = BOL
    If fstat = 1 : Rollback : GTIMOUT = 10 : Call ERREURT ("\Attachments table is locked.", 1) From GESECRAN : OKYES = 0 : Return : Endif
    Commit
    OKYES = 1
    Return

    ######################################
    #
    # For report use only - when this script is the Specific Script for the report.
    #
    $FICHIER #Set the file name on the report (when called directly).
    Gosub SETPRM : FICHIER = FILPTH
    Return
    #
    $OUVRE #When report print screen is opened, populate the File name field with the server file and path name.
    Gosub SETPRM : [M:RPT]FICHIER = FILPTH
    Return
    #
    Subprog IMPRIME(NBPAR,PARAMETRE)
    Variable Integer NBPAR
    Variable Char PARAMETRE()()
    Call EXEC(NBPAR,PARAMETRE)
    End
    #
    Subprog EXEC(NBPAR,PARAMETRE)
    Variable Integer NBPAR
    Variable Char PARAMETRE()()
    End