Workflow to automate sending crystal reports

SOLVED

Can anyone point me in the right direction for how to set up a workflow to automate the running/emailing out of a custom crystal report?  

  • 0

    Add an action to the workflow. In the action code call the etat function from aimp3.

  • 0

    This isn't an answer to your question, but we use a third party Crystal Report scheduler called Logicity to automatically send out reports.  It allows us to convert to PDF or Excel automatically.  It is simple and has worked fine for our needs. I only use the X3 workflows for email alerts like when batch tasks or imports fail.

  • 0 in reply to Glen Gillmore

    Thanks Glen, I havent used that one, but I have used other programs like that.  It is a possibility but I really wanted to get everything to automate through the system.

  • 0 in reply to Glen Gillmore

    Glen,

    I have some reports running and emailed based on the workflow as I’ve explained. What I do is I run the report as an action on the workflows start and either export it to excel or pdf. Then in the workflow I specify in the file attachment field the path to the file I just created and the workflow emails the report.

    If it needs to be scheduled and not triggered through any transaction then I can use the Recurring task management and trigger the workflow.

    I agree that this is only for someone that knows a little how to code in X3 and it is not fully GUI but it does the job. You can create the code once and then just call the action with parameters.

  • 0 in reply to Israel Braunfeld

    HI Glen,

    I was recently doing something simular and I'm curious about how (what format) you specified the path to your file. I ran into issues with this and ended up having to use the filpath formula and even then was limited to the file being in the root, or a subfolder in the root of the current X3 folder.  I'd also be intersted in more details on running the report as an action when the workflows start - you you set that up exaclty.  When you mention the code, are you talking about the Call WORKFLOW(TYPEVT,CODEVT,OPERAT,CLEOBJ) from AWRK code? I'm using that as well in  my code.

    Thanks,

    -Mike

  • 0 in reply to Mike Bailey
    verified answer

    Hi Mike,

    To set the file path, add an entry point to AIMP3 and set the FICHIER variable to your desired path. In the example below I set the path and file name and I add the soh number in the file name. Use this same logic in the workflow path.

    $ACTION

       Case ACTION

           When "IMPRIME" : Gosub IMPRIME

       Endcase

    Return

    $IMPRIME

        If ETAT = 'MyReportName'  and DESTINATION = 4 Then

           FICHIER = "C:\tmp\" + [F:SOH]SOHNUM + "_created.xls"

       Endif

    Return

    Regarding the action start, in the last tab of the workflow just select an action and specify to run at start. On the bottom enter the parameters. The action is going to call etat from aimp3

    The answer is yes to running the workflow from code

    Thanks,

    Israel

  • 0 in reply to Israel Braunfeld
    Hi Israel,

    Couldn't figure out how to private message you so, so sorry for adding to this post...

    I'm trying to figure out a way, in code, to produce PDF reports of Invoices, but not for sending/emailing or printing - just to save to a folder with a name I specify. I've tried looking at the the REPORT command, but can't find enough details about all of the parameters. Have you any experience in this and do you have any suggestions?

    Thanks,
    Mike
  • 0 in reply to Mike Bailey
    You want this to happen automatically when an invoice is posted?
  • 0 in reply to HNS
    Sorry, I was incorrect to say invoices. This is actually for a custom Crystal Report. We have a custom screen in which we will enter a Product range, and then we want to print the report to a separate PDF for each item.

    -Mike
  • 0 in reply to Mike Bailey
    Ok. But you want it to print automatically or just when you print the report, you want it to print a separate page for each one instead of all on one page?
  • 0 in reply to HNS
    On the custom screen, after entering the product range (items 00001 - 00099 for example), we'll click on OK and then we want to create a pdf for each separate item with the item number as part of the file name. So, in code, we're trying to figure out how to call the crystal report, pass it the item number and filename, specify the output type as PDF, and specify where it saves/prints the report to.

    -Mike
  • 0 in reply to Mike Bailey
    Hi,

    Below there is an example obviously this is only an example and you’d rather use parameters instead of hard coding. First you need to set the parameters of your report, in this example I only have two params. In your case there may be a begin invoice number and end invoice number param. Then run "Call ETAT()" that runs the actual crystal report with the parameters. “ZPDF” would be your PDF export printer. You would also need to set FICHIER with the desired file name and location as I've previously mentioned.



    Local integer NPPAR_MAX: NBPAR_MAX =10
    Local char TBPAR(20)(1..NBPAR_MAX)
    Local char TBVAL(250)(1..NBPAR_MAX)
    Local Char RPTNAME

    RPTNAME = 'ZMYRPORTNAME'

    TBPAR(1)="NUM"
    TBVAL(1)= "CI123456"
    TBPAR(2)="STOFCY"
    TBVAL(2)= "MYSITE"

    Call ETAT (RPTNAME,'ZPDF',"",0,"",TBPAR,TBVAL) from AIMP3
  • 0 in reply to Mike Bailey
    Ah ok, we use Sage KnowledgeSync for things like that. Another cheap solution I have used in the past is VisualCut. Its easy to set up and you can use it to "Burst" reports like that.
  • 0 in reply to Israel Braunfeld
    SUGGESTED
    Awesome! This looks great. Thank you very much!

    -Mike
  • 0 in reply to Israel Braunfeld
    Hi Israel
    I'm have a workflow which gets called from code on the click of a button in the Sales Order window.
    I need this workflow to include a pdf of the Sales Order printout

    What is the best way to achieve this?
    I've read the above pointers, but I'm not clear on what to do

    Thanks for any help

    Jay
  • 0 in reply to Israel Braunfeld
    Hi Israel

    thanks for all your advice on this post. I have manged to get my code to call a workflow which runs an action which calls etat from aimp3

    i've also used an entry point on aimp3 to set the file path for the pdf, and the workflow is set to attach this file form the same location

    Problem: the crystal report takes anything up to 15 seconds to produce the pdf, in the meantime the workflow has looked for the attachment and not found it but attached a 'non-existent' file anyway and completed sending the emails.

    how can I build in a pause after the call etat code, then look for the file and establish it exists before continuing with sending the emails. And just to complicate things, I don't really want the user staring at a paused screen until all this happens. So i'd like it just to complete in the background.

    Any ideas gratefully received
    thanks

    jfly
  • 0 in reply to jfly62
    jfly,

    I understand your pain. At the time when I was creating this I couldn't come up with an idea how to run it in the background. In my case it also takes up to 15 seconds to create my export so I just added "Sleep 15". Maybe someone else can fill in here.

    Israel
  • 0 in reply to Israel Braunfeld
    well if its good enough for you then its good enough for me!
    i thought about a loop
    for X=1 to 120
    check existence of file
    if exist : call workflow : return
    else add a second
    next
    i.e. times out after 2 mins
    not sure how to check file exists tho and still doesn't run in the background!

    thanks Israel

    jfly
  • 0 in reply to Israel Braunfeld
    Israel

    just fyi
    i managed to get my program to check for existence of the pdf before calling the workflow which avoids having to set a specific sleep time

    Local integer P, F
    For P=1 to 120
    If Filinfo("your expected filepath+filename",7) >=0
    # file exists
    # call workflow etc
    F=1 # to control display of error message infbox if file wasn't found
    P=121 # so these commands won't execute more than once
    Else
    # file doesn't exist
    sleep 1
    Endif
    Next P
    If F=0 Infbox "..... error message....." : endif


    the trickiest part was determining the file location but i just copied in the filepath from the workflow message with the server IP at the start
  • 0 in reply to Israel Braunfeld

    Hi All,

    I have similar kind of requirement.  

    Default Purchase Order Workflow is enabled. After the PO Creation ,workflow mail will trigger to users for the signature,Up to this is default functionality. Additionally  i needs to attach the PO report PDF along with that mail. 

    As advised above i created a action on the PO Workflow  and call the subprogram to create the pdf on workflow start. Below is my code:

    Subprog PRINTPO()

    Local Integer NBPAR_MAX:NBPAR_MAX=250
    Local Char TBPAR(250)(1..NBPAR_MAX)
    Local Char TBVAL(250)(1..NBPAR_MAX)
    Local Char RETVAL

    Local Integer I(10)
    Local Integer J(10)

    infbox "po"+num$([M:POH0]POHNUM)

    TBPAR(1)="commandedeb":TBVAL(1)=[M:POH0]POHNUM
    TBPAR(2)="commandefin":TBVAL(2)=[M:POH0]POHNUM
    TBPAR(3)="fournisseurdeb":TBVAL(3)=[M:POH0]BPSNUM
    TBPAR(4)="fournisseurfin":TBVAL(4)=[M:POH0]BPSNUM

    TBPAR(5)="sitedeb":TBVAL(5)=[M:POH0]POHFCY
    TBPAR(6)="sitefin":TBVAL(6)=[M:POH0]POHFCY

    TBPAR(7)="signedeb":TBVAL(7)="0"
    TBPAR(8)="signefin":TBVAL(8)="5"

    TBPAR(9)="datedeb":TBVAL(9)=[M:POH0]ORDDAT
    TBPAR(10)="datefin":TBVAL(10)=[M:POH0]ORDDAT

    TBPAR(11)="devdeb":TBVAL(11)=[M:POH1]CUR
    TBPAR(12)="devfin":TBVAL(12)=[M:POH1]CUR

    TBPAR(13)="avenantdeb":TBVAL(13)="0"
    TBPAR(14)="avenantfin":TBVAL(14)="0"

    TBPAR(15)="comsolddeb":TBVAL(15)="0"
    TBPAR(16)="comsoldfin":TBVAL(16)="0"

    TBPAR(17)="etatlivdeb":TBVAL(17)="0"
    TBPAR(18)="etatlivfin":TBVAL(18)="0"

    TBPAR(19)="etatfacdeb":TBVAL(19)="0"
    TBPAR(20)="etatfacfin":TBVAL(20)="0"

    TBPAR(21)="codimp":TBVAL(21)="0"

    TBPAR(22)="filnam":TBVAL(22)="C:\Sage\X3V11\folders\PILOT\tmp\"+[M:POH0]POHNUM+".pdf"


    Call ETAT("BONCDE2_EMAIL","FILEPDF","",0,"",TBPAR,TBVAL)From AIMP3

    End

    After that i created a copy of default PO report and created -  BONCDE2_EMAIL

    I created a specific script ZBONCDE and call this in the specific script of the BONCDE2_EMAIL report.  below is my code.

    Subprog IMPRIME(NBPAR,PARAMETRE)

    Local Integer YTEMP

    For YTEMP = 0 To 30

    If [M:AIP]TBPAR(YTEMP) ="filnam"

    FICHIER = [M:AIP]TBVAL(YTEMP)
    FMTFIC = 29
    infbox FICHIER

    Break

    Endif

    Next

    End


    $ACTION

    Case ACTION

    When "FICHIER" : Gosub FICHIER From ZBONCDE
    #When "IMPRIME" : Gosub IMPRIME From ZBONCDE


    When Default

    Endcase
    Return

    $FICHIER

    #If GSERVEUR = 0

    If dim(FICHIER)

    Local Integer YTEMP

    # Find the parameter named filnam, and override the report file name with this value


    For YTEMP = 0 To 30


    If [M:AIP]TBPAR(YTEMP) ="filnam"

    FICHIER = [M:AIP]TBVAL(YTEMP)


    Break


    Endif


    Next


    #Endif

    Endif


    Return

    But after creating the purchase order the pdf file is not getting created.

    Even though if i call the same code from SPEPOH  using the following method the file is creating

    $APRES_CRE

    Kindly advise how to resolve this.

    Thanks

  • 0 in reply to Israel Braunfeld

    Does anyone know how to use a command to have Outlook open and send the email that way??