Attachment names look cryptic on workflows? Read below to learn how to fix that

5 minute read time.

Hello readers, today we are going to be looking at an older topic. It may be older but it’s still relevant to current versions. We are going to explore the idea behind changing workflow email attachment names. Specifically, about how to change the naming convention of the actual attached files. This could be any of the following: txt, pdf, doc, docx, csv, xlx, and xlsx. Pretty much any selection from the destination function minus RPT files. Apparently crystal report designer (CRD) does not play nice with exporting from X3, who knew? If you ran into as many issues as I have with RPT files you would ignore them too. Anyhow, let’s get started…

So, before you start, you’re going to need a workflow rule and assignment, and other workflow stuff (that I cannot think of at the moment) already configured. I am not going to cover how to setup a workflow to work with Sage X3, not because I dislike workflows in general, but because it would be a mile-long blog if I did. If you don’t have one setup you can stop right here and check out our knowledge KBID #55644. It’s a bit older kb as its written around v6 but its content is still good.

 

Well, if you have a workflow currently working and sending emails with attachments, you can skip that top part and keep following along. So, I would assume that your attachments have weird cryptic naming system. That’s because its hard coded in 4GL code on how to process the name of the save (and then attached) file. The way around this is to utilize an Entry Point. What is an entry point, you say? Well, without going into extreme detail, an entry point is like a stop in the code where you can safely interject your own custom code into the routine without having to modify the standard base coding. If you want to read more on entry points, you can check out the online help topic here. If you want to see a listing of all the available entry points, you can find them here.

In our case we are going to utilize the entry point MESSAGE. Yeah, that the name of the entry point… MESSAGE. And yes, I know, its not a message it’s an attachment, but that’s what it’s called. Anyways, the MESSAGE entry point come from the AWRK code, which you can search the online help at the above links and find more details on it. All you need to know is that MESSAGE will be our stop to add our code to it. Next you want to take the following information and add it to a text file.

$ACTION

Case ACTION

  When "MESSAGE" : Gosub MESSAGE

Endcase

Return

$MESSAGE

Local Char FICHIER(80)

Local Integer STAT

##-- new file name:  hardcoded or you can built it

FICHIER=filpath("","","")+"OTHER_NAME.pdf"

Call MOVE (PCEJOI(NBJOI),FICHIER,STAT) From ORDSYS

PCEJOI(NBJOI)=FICHIER

Return

 

You can also get this same section from the online help here.

Once you have it in a text file, save it. We will need it later. So what I do is I name the file the same as the entry point so I remember where it goes. I called my saved text file MESSAGE.src. I added src because that the extension for 4GL code and we will need it as a src when we compile for use.

Note: this is default from online help

 

There are additional options you can use. See my screenshot below:

For the sake of this blog, I will be using the default one (2 up) from here. So now we are going to take the MESSAGE.src and copy it to the <Endpoint>\TRT directory. For me I am using the Demo endpoint SEED, so I will be copying my file to ..SEED\TRT directory.

So, once you have it here you can go ahead and log in. You’re going to want to find the script editor. It should be in the same place for all the versions (or at least I think so). You’ll find it under Development module, Script Dictionary and Scripts Section.

 

Launch that function. It is also known as ADOTRT. When you get it open your going to want to type in the new source file name (minus the src at the end). It should look similar to mine.

If its right it should load all the contents of the src file, and you should be able to see it. After that you are going to want to click on Compile to compile the code into an ADX extension file. This is so the system can use it. If you get no popup then it worked. It only popups on errors. Plus, you can always check the TRT folder and see if an ADX file was created.

Lastly, now that you have the adx file, is to add it to the Entry Point Function. We do this by utilizing the Entry point function under development module. Its actually in the same place as script editor function.

Entry point function is also known as GESAPE. Here, we are going to add a new record and use the MESSAGE.adx (in my case) and add it as a request. I color coded the columns for a reason, as you will see in a minute.

I’ll explain the colors:

Yellow: This is the Type of entry point. In this case we select Entry Point

Orange: This is the Standard Code that you want to attach your Specific (aka SPE) to. Its typically the one with the Entry point in it.

Purple: this is the name of your specific script. Its good to note that calling the script by the entry point name helps.

Pink: this is for the module that its in. If you don’t know the module, just select Supervisor.

So, save that and exit. We should be good to go. Make sure you do all of this in a Test Environment to make sure you do not break anything.  At this point you would want to review KBID #55644 and make sure you have APRINT or equivalent workflow setup to properly use it.

Example:

As you can see, I left the “Other name” instead of changing it. It was so you can see where you will see where it will show up. Now you know. Don’t forget to check out those links throughout the Post for some more detailed information.

  • Additional notes:
    Also, I noticed the root filepath will be filed with the renamed reports and not cleaned up automatically as part of the workflow completion.

  • Hi, came from googling this topic: https://www.sagecity.com/us/sage_x3/f/general-discussion/84489/report-attachment-in-email/509559
    and ended up reaching here.

    One question, how do I fix the sending message?

    The attachment name is fine

  • #YBARCELONA
    
    IF BOUT="B" & [M:SOH0]SOHTYP="NEG" & find([M:SOH2]STOFCY,"")>0 & LEFT$([F:SOH]REP,2)<>"S4"
     If clalev([F:SOH])=0 Local File SORDER [SOH] : Endif
     If clalev([F:SOQ])=0 Local File SORDERQ [SOQ] : Endif
     If clalev([F:ITM])=0 Local File ITMMASTER [ITM] : Endif
     If clalev([F:STO])=0 Local File STOCK [STO] : Endif
     If clalev([F:STA])=0 Local File STOALL [STA] : Endif
     Link [SOQ] With [SOH]SOH0=[SOQ]SOHNUM as [YSO]
     Filter [YSO] where [M:SOH0]SOHNUM=[SOQ]SOHNUM
     For [YSO]
      Link [STA] With [STO]STO0=[STA]STOFCY;[STA]STOCOU as [YST]
      Filter [YST] where [STA]VCRNUM=[SOQ]SOHNUM and [STA]VCRLIN=[SOQ]SOPLIN and [STA]VCRSEQ=[SOQ]SOQSEQ
      For [YST]
    #  Local Integer  STA
    #  Local Integer  TRACE
    #  Local Char      FIC_TRACE(250)
    #  Local Char      ISSUERMAIL(250)
    #  Local Char      A_USER(250)(1..)
    #  Local Char      CC_USER(250)(1..)
    #  Local Char      HEADER(250)
    #  Local Clbfile   BODY(0)
    #  Local Char      ATTACHMENTS(250)(1..)#(1..)
    #  Local Char MYPATH(250)
       Local Char VFOLDER(250)
       Local Char YLOT (250)
    #  Local Char FICCLI(250)
       VFOLDER=[M:SOH0]SOHNUM
       YLOT=[F:STO]LOT
    #  A_USER(1)=""
    #  CC_USER(1)=""
    #  HEADER="DOCUMENTS"+" - "+[M:SOH0]SOHNUM
    #  ISSUERMAIL=""
    #  TRACE = 2
    #  ATTACHMENTS(1)="[XXX]/COA/"+[F:STO]LOT+".pdf"
      #  Infbox [F:STO]LOT+[F:STA]VCRNUM #TEST
    #  Append BODY , 'Blabliblo '+chr$(10)
    #  STA =func ASYRMAIL.ASEND_MAIL(GACTX,ISSUERMAIL,A_USER,CC_USER,HEADER,BODY,ATTACHMENTS,TRACE)
    #    If STA <> [V]CST_AOK Then
    #                 infbox( mess(1163,196,1))
    #    else
    #                 infbox("Email was sent nice!")
                     MYPATH= filpath(func F_ATTACH_VOLUME() + "\COA",YLOT,"PDF")
                     If filinfo(filpath("XXX\COA\",YLOT,"PDF"),0)>0
                        Call ADD_ATTTACHMENT(func F_ATTACH_VOLUME(), MYPATH, "SOH", VFOLDER) From YFUNOBJTXTEXT2
    					  #Call SEND_PDF([F:SOH]SOHNUM) From YM010WRKREL
                         infbox("PDF Attaché "+YLOT+".PDF")
                     Elsif filinfo(filpath("XXX\COA\",YLOT,"PDF"),0)<0
                         infbox("Pas de Fichier pour "+YLOT)
                     Endif
    #    Endif  
      Next
     Next
    ELSIF BOUT="B" & [M:SOH0]SOHTYP="NEG" & LEFT$([F:SOH]REP,2)="S4" then
      Call ERREURT("Cette fonctionnalité n'est pas disponible pour ce client. Si un message d'erreur est apparu, merci de la corriger avant de continuer.", 0) From GESECRAN
    ENDIF

    I hate this website. Hope it helps. I never learn L4G, I don't know if good code.

  • Thank you for your suggestion. It is much appreciated!

  • Hi,

    Apparently it should be as simple as:

    FICHIER=new file : NBJOI+=1 : PCEJOI(NBJOI)=FICHIER