Change Report Name when printing

Hi There

For Sage X3 V12 

I am trying to get Sage to print/save with different file name than the Crystal Report name

Have added entry point AIMP3 custom script ZAIMP3

Here is my code

$ ACTION 
Case  ACTION 
    When  "PARAM"     : Gosub PARAM
 Endcase 
Return
 
 
$PARAM 
If  [F:ARP]RPTCOD = "ZPO"  
    Local  Char XPARAM (250) 
    XPARAM = chr$(1)+"E:\Sage\folders\TEST\ATT\"+[F:POH]POHNUM+".pdf" 
    Call SETPARAM("_ExportFile",NBPAR,PARAMETRE,XPARAM) From ETAT
 Endif 
Return

I have complied it and logged out and back in again

It's not working as expected, receive no errors but it's not doing anything

  • We have code that renames a PDF of the invoice to customer + Invoice number + SO number + customer PO # and all fixed length with zero fill.  So PO always starts at position X.   I didn't program it.    Greytrix did it to my specs.   It was difficult.   It took significant time to debug it. 

    If you get no other help, we can ask Greytrix or we could pull the code and look at it perhaps. 

  • in reply to Stephen

    Thanks Stephen

    If you can perhaps get the code that would be great,  I just need a starting point. 

    My workaround was to use AIMP3 entry point to write to the Server. Once the file is written it pops up with a notification that provides a URL to the file to open it. I defaulted the print destination to print to file to achieve this. It's not ideal but it's working for now. 

  • in reply to Moomin Rider

    >>Once the file is written it pops up with a notification that provides a URL to the file to open it. 

    This seems like what Greytrix came up with.    It created a temp file as a PDF and saved it.  Then it openned the file and renamed it.    Then it proceeded to preview mode on the new name. 

    We had issue with timing and don't remember the cure but it may have just been a delay.  We would attempt to open the file in preview mode and it wouldn't be there yet.   This was the biggest issue during the whole process.

  • in reply to Stephen

    I think they might have done the same as what I did. 

    I have since revised my dev. Rather than it giving it a link with notification I have now made it so that is saves to the Transactions under attachments with the Correct document number like below..

  • in reply to Moomin Rider

    I would be very interested in how you did this if you are willing to share.

  • Based on the code you provided, it seems that you are trying to use a custom script to set the export file name for a specific report ("ZPO") to a value that includes the PO number. However, there are a few potential issues with your code that could be causing it not to work:

    1. The code you provided only handles the "PARAM" action. Depending on how your report is configured, it may be necessary to handle other actions as well (e.g., "PRINT", "PREVIEW", etc.).

    2. The variable XPARAM is defined as a local variable within the PARAM subroutine, which means that it will not be accessible outside of that subroutine. In order to set the export file name for the report, you will need to pass the value of XPARAM to the SETPARAM function as a parameter.

    3. The value of XPARAM is being constructed using a hardcoded file path ("E:\Sage\folders\TEST\ATT") and the value of the PO number field ("[F:POH]POHNUM"). Depending on your environment and the configuration of your report, these values may not be correct. You may need to modify the file path and/or the field name in order to properly construct the export file name.

    To help troubleshoot the issue further, you could try adding some logging statements to your code to see what values are being passed to SETPARAM. For example, you could add a line like this after the XPARAM assignment:

    Print "Export file name: " + XPARAM

    This will print the value of XPARAM to the log file, which you can then review to ensure that it is being constructed correctly. Additionally, you may want to check the log files for any errors or warnings related to your custom script. The log files can typically be found in the \adm folder of your Sage X3 installation.