SAP GUI Scripting - Download attachments from GOS (Attachment List)

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ก.พ. 2017
  • The script in this video downloads attachments from multiple sales orders. It used the Global Object Services / Attachment List in VA03 to download the documents attached to the order. Since GOS is available for many business documents in ERP this script can be adapted to be used for invoice, PO, etc.
    Link to the Excel document: drive.google.com/file/d/0Bw1X...
    GUI Scripting playlist: • SAP GUI Scripting and ...
    Link to the first video with the basics: • SAP GUI Scripting 1 - ...
    All my GUI scripting files on Github (in case you cannot access the above link):
    github.com/nygma2004/km/tree/...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 68

  • @williamshields8401
    @williamshields8401 2 ปีที่แล้ว +4

    Thanks for this! I was able to modify your base to work for my needs and download attachments for tcode fb03! Literally days of work will be saved for my one project and many projects to come.

  • @inigosanchez-ostizchivite5441
    @inigosanchez-ostizchivite5441 3 ปีที่แล้ว +1

    Amazing Work. Very clean and easy to understand. That´s why you are a genius!!

  • @dominiquenoel939
    @dominiquenoel939 7 ปีที่แล้ว +2

    Thank you for your advices.

  • @stephanjannoff2979
    @stephanjannoff2979 6 ปีที่แล้ว +1

    Very helpful, thanks for sharing

  • @idbenomar
    @idbenomar 7 ปีที่แล้ว +1

    thank you sir for this ..much appreciated.

  • @oodaikiran
    @oodaikiran 6 ปีที่แล้ว +2

    Thank you for brilliant videos. I just have one question how can I download documents in "Archived" type

  • @bhaskarbasam1
    @bhaskarbasam1 6 ปีที่แล้ว +1

    Hi Csongor, I've got the similar requirement to upload the attachments instead of download the attachments into the display fi document data (FB03). We have folders created with doc numbers and each folders have files in them and user want to upload the files in the respective document numbers. Can you pls help me for the vba code to read the respective doc folder to upload the attachments.

  • @kevinxu3859
    @kevinxu3859 7 ปีที่แล้ว +2

    thanks for your sharing.

  • @vigneshajithkumar
    @vigneshajithkumar 4 ปีที่แล้ว

    Please advise, how to download the invoice showing "Archived" type

  • @JustinDavey
    @JustinDavey 4 วันที่ผ่านมา

    This is very useful. I got a point where I used Export->Local file->unconverted to avoid the Windows popup (Export file) screen. However now it only exports 1kb file size. At least I have retrieved the filenames which helps me out somewhat. Not sure how to troubleshoot this issue.

  • @angelawang680
    @angelawang680 2 ปีที่แล้ว +2

    Hi Csongor, thanks for the great video, I watched last night and was very inspired! I am running into the issue for Window dialogue instead of GUI dialogue when clicking the attachment to download, it opens the window popup which cannnot be recorded unlike what's in your video (at 4:43). I turn off the setting " show native MS windows dialogs" in scripting setting, but it still pops up the windows screen to save as. Is there anyway you could help me to figure out the best way to resolve this? Thanks so much!

    • @csongorvarga
      @csongorvarga  2 ปีที่แล้ว

      Yes, unfortunately I have bad news. Those cannot be scripted. Like the Open, Save, Print dialogs or the Adobe Acrobat PDF preview window. I think technically it is possible in VBA to catch a handle of another window and send key commands to it (like Enter key), but I never been able to make it work.

    • @angelawang680
      @angelawang680 2 ปีที่แล้ว

      @@csongorvarga Thanks a lot for your quick reply! I will keep exploring it.

  • @Marktommurphy
    @Marktommurphy 4 ปีที่แล้ว

    HI, Can this be done with T-code FB03, which is display document number. I am looking to download attachments into a folder in SAP FV03.

    • @csongorvarga
      @csongorvarga  4 ปีที่แล้ว

      Sorry, I don't know that transaction and I don't have access to SAP now to check.

  • @rajkumargerard5474
    @rajkumargerard5474 6 ปีที่แล้ว

    Hello Csongor, I have got a query for a TCode: VF03 where I'm trying to search with the Assignment/Ref number and copy the Description and the Net value from the SAP table. I trying to copy this from VBA code but not sure how to use it. Please could you help me....

    • @csongorvarga
      @csongorvarga  6 ปีที่แล้ว

      Create a recording, in which you select the fields that you want to get the value of. You will see these fields appearing in the recording with the .SelectedItem method. Just replace that to the .Text property. That should work for most of the UI fields.

    • @rajkumargerard5474
      @rajkumargerard5474 6 ปีที่แล้ว

      Thank you so much for the reply Csongor.. I'm not finding the method you had mentioned. Here is actual code after i execute the query : "session.findById("wnd[0]/usr/tblSAPMV60ATCTRL_UEB_FAKT/txtVBRP-NETWR[4,1]").setFocus
      session.findById("wnd[0]/usr/tblSAPMV60ATCTRL_UEB_FAKT/txtVBRP-NETWR[4,1]").caretPosition = 20". Please help
      Also requst you to make a video on my topic which will help many....

  • @Grichecth
    @Grichecth 6 ปีที่แล้ว

    Hi, I tried running this after changing my SID & Client & entering a known order with attachments but it gave me:
    Run-time error '91':
    Object variable or With block variable not set.
    I tried debugging but I'm not sure where to start. Any tips? Thank you!

    • @csongorvarga
      @csongorvarga  6 ปีที่แล้ว

      It sounds like the "SAP GUI Scripting" library is not linked to the Excel. In the VBA Editor select Tools / Preferences and make sure the SAP GUI Scripting library is ticked. I mention this in the video.

    • @Grichecth
      @Grichecth 6 ปีที่แล้ว

      Thank you kindly for your time to reply. I was thinking that too but it is definitely checked. I verified the path as well. I'm running on Office 2016, do you know if that would affect that?

  • @zacharyreed3860
    @zacharyreed3860 3 ปีที่แล้ว

    Hi Csongor, once a week I pull multiple ZPAR, ZINVR and ZJ01N reports from SAP. I am trying to automate the process using SAP GUI scripting but having some difficulties. Can I automate all extractions from SAP using this method?

    • @csongorvarga
      @csongorvarga  3 ปีที่แล้ว

      I don't know these transactions, I don't know how they work. If the transaction has a button to download the report, you can automate it. The only issue I can see if there is a Windows "Save as" dialog in the process, or for example the report is generated as a PDF and you need to click Save within the PDF document viewer to save it. These two are not SAP GUI screen therefore GUI scripting will not record it.

  • @PieterEsterhuizen
    @PieterEsterhuizen 3 ปีที่แล้ว

    Good day, I would like to understand how you action the save function with a pop-up windows dialogue in SAP Script. The moment my Save option pops-up my script stops and waits for a manual intervention to save {enter}. I have managed to create a separate script for the windows dialogue but can call it in the SAP script as it waits for the window to close before proceeding.

    • @csongorvarga
      @csongorvarga  3 ปีที่แล้ว

      I don't know. That is a Windows Dialog and this is why it does not get scripted. You can google how you can get the handle of a windows window and send and enter key to that windows which will be the Save button. But I never done this before, I don't have an example code.

    • @PieterEsterhuizen
      @PieterEsterhuizen 3 ปีที่แล้ว

      @@csongorvarga did a bat file to execute in the cmd.

    • @zoltanholl8326
      @zoltanholl8326 2 ปีที่แล้ว

      Possible solution is to go to Option / Accessibility & Scripting / Scripting and uncheck the "Show native Microsoft Windows dialogs". Its work for us.

  • @lizcrites9056
    @lizcrites9056 ปีที่แล้ว +1

    Hi Csongor - Thank you so much for the great video. Can you tell me how to handle if there are no attachments?

    • @csongorvarga
      @csongorvarga  ปีที่แล้ว

      Before you start downloading you can check if there are any items in the view.

    • @lizcrites9056
      @lizcrites9056 ปีที่แล้ว

      @@csongorvarga I was able to get everything to work, but am having trouble figuring out what and where to put the error handling for no attachments.
      I'm sorry - I'm green at this. I know just enough to get around, but not smoothly. :-) Thank you in advance for your help! I've been trying to solve this problem for months and am very grateful for your video.
      Could you please show me how to include that check in your code below?
      'Comment the below TWO LINES if you want to save all documents into the same folder
      'Folder = Folder + "\" + DocNo
      'FolderCreate Folder
      'Saving the attachment list object for later use
      Set alist = objSess.FindById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell")
      'Cycle through the items in the attachment list
      For i = 0 To alist.RowCount - 1
      'Select the item in the view
      alist.CurrentCellRow = CStr(i)
      alist.selectedRows = CStr(i)
      AddLog "Save", "Saving document " + alist.GetCellValue(i, "BITM_DESCR"), vbBlack

      'Click on the export button
      alist.PressToolbarButton "%ATTA_EXPORT"
      'This checks if the window is still the attachment list view: download is not possible, pop-up did not appear
      If objSess.ActiveWindow.GuiFocus.Text = "SAPGUI.GridViewCtrl.1" Then
      'Log failed download
      AddLog "Save", "Document save failed " + alist.GetCellValue(i, "BITM_DESCR"), vbRed
      Else
      'Proceed with the download by specifying the folder and file name
      objSess.FindById("wnd[2]/usr/ctxtDY_PATH").Text = "c:\att"
      'Comment the below TWO LINES if the file name should not be prefixed with the document number
      Filename = objSess.FindById("wnd[2]/usr/ctxtDY_FILENAME").Text
      objSess.FindById("wnd[2]/usr/ctxtDY_FILENAME").Text = DocNo + "_" + Filename
      objSess.FindById("wnd[2]/usr/ctxtDY_PATH").SetFocus
      objSess.FindById("wnd[2]/usr/ctxtDY_PATH").caretPosition = 7
      objSess.FindById("wnd[2]/tbar[0]/btn[11]").press
      AddLog "Save", "Attachment " + alist.GetCellValue(i, "BITM_DESCR") + " downloaded", vbBlack
      End If

  • @hamadamohsen9279
    @hamadamohsen9279 5 ปีที่แล้ว

    I need Script to Help Save File when Save as Window appear in SAP , Please Help.

    • @csongorvarga
      @csongorvarga  5 ปีที่แล้ว +1

      You cannot. Save as window is a Windows System dialog, that cannot be scripted with GUI scripting. Maybe try using a different transaction. In SAP GUI 7.40, there is also an option which says "use GUI dialog windows". Try ticking that and see if you get a SAP save dialog instead of the Windows dialog.

  • @patriciajamaicabugia1879
    @patriciajamaicabugia1879 4 ปีที่แล้ว

    Hi Varga,
    I tried to create a macro with the same way you've created it. Unfortunately, I keep on having a Completed-Failed-COmpleted-Failed status. Can you help me with this please?

    • @csongorvarga
      @csongorvarga  4 ปีที่แล้ว

      Check what is happening in the GUI. Maybe there is a pop-up on your GUI screen that you script is not handling correctly.

    • @patriciajamaicabugia1879
      @patriciajamaicabugia1879 4 ปีที่แล้ว

      @@csongorvargaWould you know please what can I remove just so it will automatically pick the first file in the list? Not the entire data. Thank you very much, your tutorial is super helpful

    • @patriciajamaicabugia1879
      @patriciajamaicabugia1879 4 ปีที่แล้ว

      I copy your code and replaced the transaction code and did the scripting. I just need to change and let the system pick up only the first file, not the entire files.

  • @benskerrett5856
    @benskerrett5856 2 ปีที่แล้ว +1

    Amazing solution and excellent presentation.
    I have modified the script so it works for QM Certificates, the issue I am having is when there are multiple documents attached.
    The system we use, gives each attachment the same name, so when it saves to the folder, the second file over writes the first file.
    Are you aware of a solution please, which would allow me to use the "Created on Date" and "Created on Time" fields, as the file name? This would then make each file unique.
    Thanks Again

    • @csongorvarga
      @csongorvarga  2 ปีที่แล้ว

      Well, you have a few options. If there is any unique field on the list view, you can read the content like I read the Filename (Filename = objSess.findById("wnd[1]/usr/ctxtDY_FILENAME").Text) and expand it to the filename. Or you can just use the i loop variable to be added to the filename: objSess.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = DocNo + "_" + Filename + "_" + i
      That will generate files with an incrementing number at the end.

    • @benskerrett5856
      @benskerrett5856 2 ปีที่แล้ว

      @@csongorvarga thanks again, I will give it ago.

  • @Hisense12345
    @Hisense12345 2 ปีที่แล้ว

    Great video, is it possible to get it to work to download attachments for notifications?

    • @csongorvarga
      @csongorvarga  2 ปีที่แล้ว

      Most probably. Anything in GUI can be scripted.

  • @ramanreddy7181
    @ramanreddy7181 5 ปีที่แล้ว

    could you please share the xl file for this

    • @csongorvarga
      @csongorvarga  5 ปีที่แล้ว

      Link is in the video description.

  • @trunghieudluk29
    @trunghieudluk29 5 ปีที่แล้ว

    how find SID + Client ???

    • @csongorvarga
      @csongorvarga  5 ปีที่แล้ว

      Right side of the status bar a small menu where it shows your SID and client.

  • @alejandrolarallao5316
    @alejandrolarallao5316 ปีที่แล้ว

    No puedo 😢

  • @murtuzasadriwala138
    @murtuzasadriwala138 11 หลายเดือนก่อน

    Hi, I managed to change script for Material Master attachment download. I tested in test system it works very nice but when I try to use in production system it gets stuck at point of saving file. Like it always select last location opened it doesnt update location to folder name of material and save the file. Why its acting different in different system? I couldnt understand it.

    • @murtuzasadriwala138
      @murtuzasadriwala138 11 หลายเดือนก่อน

      Hi, I notice in one system the Export file is SAP GUI screen and another windows screen. Where it is window screen it does not work.

    • @csongorvarga
      @csongorvarga  11 หลายเดือนก่อน

      @@murtuzasadriwala138 In the GUI options, under Accessibility & Scripting / Scripting there is a "Show native Microsoft Windows dialogs" that I uncheck. But that setting is not system dependent. Unfortunately I have no idea why different systems act different. There could be a system setting that I am not aware of.

    • @murtuzasadriwala138
      @murtuzasadriwala138 11 หลายเดือนก่อน +1

      @@csongorvarga Thanks for reply. I analysed and found that difference is due to different basis patch . So the system in which it is not working has older patch. So unfortunately I wont be able to use the script. Quite annoying as SAP has not given that control somewhere in settings to modify. This was really good learning though and its quite helpful too 🙂thank you.

    • @csongorvarga
      @csongorvarga  11 หลายเดือนก่อน

      @@murtuzasadriwala138 Interesting, thanks for sharing this detail.

  • @shahnonu
    @shahnonu 3 ปีที่แล้ว

    Can we have the excel with coding

    • @csongorvarga
      @csongorvarga  3 ปีที่แล้ว

      As I said, link in the video description.

  • @danycoelho7277
    @danycoelho7277 6 ปีที่แล้ว

    Hi Csongor! I'm doing a vba form for displaying invoices using FB03, however I'm struggling in the code. I want to look by doc number which is inserted in a textbox, then after applied the doc number in the textbox, I have a button to display. I share the code, hope you may give some idea (thanks in advance :) ):
    Public Sub Display_Click()
    Dim invoice As String
    'Se the defaults
    W_System = Range("System").Value
    If Not IsObject(Sapplication) Then
    Set SapGuiAuto = GetObject("SAPGUI")
    Set Sapplication = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(Connection) Then
    Set Connection = Sapplication.Children(0)
    End If
    If Not IsObject(session) Then
    Set session = Connection.Children(0)
    End If
    If IsObject(WScript) Then
    WScript.ConnectObject session, "on"
    WScript.ConnectObject Sapplication, "on"
    End If
    session.findById("wnd[0]").maximize
    session.findById("wnd[0]/tbar[0]/okcd").Text = "/FB03"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = invoice
    session.findById("wnd[0]/usr/ctxtRF05L-BUKRS").Text = "CC"
    session.findById("wnd[0]/usr/txtRF05L-GJAHR").Text = "FiscalYear"
    session.findById("wnd[0]/usr/txtRF05L-GJAHR").SetFocus
    session.findById("wnd[0]/usr/txtRF05L-BELNR").caretPosition = 3
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
    session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"
    session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").setCurrentCell 1, "BITM_DESCR"
    session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "1"
    session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").pressToolbarButton "%ATTA_DISPLAY"
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[3]").press
    End Sub

    • @csongorvarga
      @csongorvarga  6 ปีที่แล้ว

      I don't know FB03 much. I can see that you have created a new variable invoice, and you are using that in the code, but I don't see where you give that variable a value? Is that what you are missing? There is a InputBox method in VBA you can use. That will show a pop-up where you can enter the invoice value. Add this line below the Dim invoice.. line:
      invoice = InputBox("Enter the invoice number")
      I hope that's what you meant.

    • @danycoelho7277
      @danycoelho7277 6 ปีที่แล้ว

      Hi! I have the form with a textbox that I named "invoice", in this textbox I introduce the doc number and then, press a button to display the attachment. Following your suggestion, I will create the variable, and so on. The code you wrote must be included in the declaration of the module or in the form? Thanks a lot!

    • @danycoelho7277
      @danycoelho7277 6 ปีที่แล้ว

      I have in the code of the button for display:
      Dim docnumber
      docnumber = invoice
      -But, the program is giving me error in the line below:
      session.findById("wnd[0]/usr/ctxtVBAK-VBELN").Text = docnumber

    • @csongorvarga
      @csongorvarga  6 ปีที่แล้ว

      Sorry, I forgot about this. What is the error? Can you also change the "Dim docnumber" to "Dom docnumber as String". You might have a type issue. Can you also put a breakpoint and check what is the value of invoice and docnumber? Just to make sure it can pass the value in the correct type.

  • @fernandoventura8726
    @fernandoventura8726 5 ปีที่แล้ว

    Link off, please help me, i need this code. Thanks

    • @csongorvarga
      @csongorvarga  5 ปีที่แล้ว

      Link is working. Google Drive may be blocked by your company.

    • @fernandoventura8726
      @fernandoventura8726 5 ปีที่แล้ว +1

      @@csongorvarga yes... true... download is complet. thanks a log, very nice work!

  • @soumyakchakraborty7818
    @soumyakchakraborty7818 ปีที่แล้ว

    Hiii thanks for this video. Please make a video on reverse case. Like I want to attach one file in multiple sap vendor codes. How can I automate this process with VBA. T-code for entering vendor master is BP.

    • @csongorvarga
      @csongorvarga  ปีที่แล้ว

      I did a video on the upload. It was not to vendors, but for a different object.

    • @soumyakchakraborty7818
      @soumyakchakraborty7818 ปีที่แล้ว

      @@csongorvarga ok please share link of that video. I can get some help in my requirement.

  • @KelvinHayes
    @KelvinHayes 2 หลายเดือนก่อน +1

    Love this script!!! I have this working on my laptop but having issues getting it to run on a coworkers laptop. I'm getting a compile error. "Can't find project or library" at line "Set alist = objSess.FindbyId("wnd[1]/user/cntlCONTAINER_0100/shellcount/shell"). Any ideas on this? Thanks!

    • @csongorvarga
      @csongorvarga  2 หลายเดือนก่อน

      This is strange, I mean if library is missing, it would fail almost the first line of code when it wants to connect to the session, not later like here. Can you check in Tools / Preferences that the library is properly added?

    • @KelvinHayes
      @KelvinHayes 2 หลายเดือนก่อน

      @@csongorvarga They have the SAP GUI Scripting API box checked just like me.

    • @csongorvarga
      @csongorvarga  2 หลายเดือนก่อน

      @@KelvinHayes Uh, in that case I have no idea. Does it stop in that line? Does it connect to the SAP session?