automationguy128 Posted June 28, 2018 Share Posted June 28, 2018 Using the script recording and playback feature on SAP, when trying to compile a script that selects lower toolbar buttons, keep getting compile errors in AutoIt. I want to be able to automate the clicking of the button shown in the picture. Other picture shows the error I am receiving in AutoIT for the following code: $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_VIEW" $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&PRINT_BACK_PREVIEW" "error: Statement cannot be just an expression" Link to comment Share on other sites More sharing options...
BrewManNH Posted June 28, 2018 Share Posted June 28, 2018 Instead of pictures, post your code. Earthshine 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
automationguy128 Posted June 28, 2018 Author Share Posted June 28, 2018 14 minutes ago, BrewManNH said: Instead of pictures, post your code. Its just those two lines in my first post, everything else works, it just seems to be the lower toolbar that I am getting errors with. I just want to know if its a syntax issue, as this is what was generated from SAP's script recording feature and can't find anything online similar to this issue. Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 well, I can't tell without code to play with. there is obviously an issue with that error present My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
BrewManNH Posted June 28, 2018 Share Posted June 28, 2018 22 minutes ago, automationguy128 said: Its just those two lines in my first post, everything else works, If you don't post your code, no one is going to be able to answer your questions. We have a variable that we don't know what it's set to, and an error saying that your line is written wrong without having the lines that surround it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
automationguy128 Posted June 28, 2018 Author Share Posted June 28, 2018 expandcollapse popup#include <Date.au3> #include <MsgBoxConstants.au3> Dim $SAPROT, $SapGuiAuto, $application, $connection, $session ShellExecute("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe") WinWait("SAP Logon 740") ControlClick("SAP Logon 740", "",1068) WinActivate("SAP") sleep(2000) ;SAP GUI Defined (excluded) ;Enter the client number (excluded) ;credentials entered (excluded) sleep(3000) $session.findById("wnd[0]/tbar[0]/okcd").text = "sk01" $session.findById("wnd[0]/tbar[0]/btn[0]").press $session.findById("wnd[0]/usr/cntlGRID_CONT0050/shellcont/shell").currentCellRow = 75 $session.findById("wnd[0]/usr/cntlGRID_CONT0050/shellcont/shell").firstVisibleRow = 66 $session.findById("wnd[0]/usr/cntlGRID_CONT0050/shellcont/shell").selectedRows = "75" $session.findById("wnd[0]/tbar[1]/btn[8]").press $session.findById("w nd[0]/tbar[1]/btn[17]").press $session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellRow = 4 $session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "4" $session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell $session.findById("wnd[0]/tbar[1]/btn[8]").press $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_VIEW" $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&PRINT_BACK_PREVIEW" $session.findById("wnd[0]/tbar[1]/btn[45]").press My bad guys, pretty new to this. Code is attached Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 (edited) I looked at the doc for it. in C# and VB you do it like this, I think this may work for you as well. $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton ("&MB_VIEW") $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem ("&PRINT_BACK_PREVIEW") Edited June 28, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
automationguy128 Posted June 28, 2018 Author Share Posted June 28, 2018 2 minutes ago, Earthshine said: I looked at the doc for it. in C# and VB you do it like this $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton ("&MB_VIEW") $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem ("&PRINT_BACK_PREVIEW") Although it now compiles, I receive the automation error "Error: The requested action with this object has failed" Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 afraid of that..... hmmmmm all the samples show it the way your recorded made it too. $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_VIEW" $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&PRINT_BACK_PREVIEW" what version of AutoIt are you using? maybe you need an older version? My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
automationguy128 Posted June 28, 2018 Author Share Posted June 28, 2018 2 minutes ago, Earthshine said: afraid of that..... hmmmmm all the samples show it the way your recorded made it too. $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton "&MB_VIEW" $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem "&PRINT_BACK_PREVIEW" what version of AutoIt are you using? maybe you need an older version? autoit version v3.3.14.2 Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 (edited) I am getting same compile issues update, I searched the FORUM for an UDF, they have an SAP UDF and they did what I had suggested and the guy said it worked, putting the thing in parenthesis. Edited June 28, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 (edited) I have figured out this. I gave you the right answer to enclose it in () because the SAP recorder just spits out VBScript However, you may need to add an error handler to see what is wrong with that object you refer to in order to find out more. It looks like you are using COM? Edited June 28, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
automationguy128 Posted June 28, 2018 Author Share Posted June 28, 2018 5 minutes ago, Earthshine said: I have figured out this. I gave you the right answer to enclose it in () because the SAP recorder just spits out VBScript However, you may need to add an error handler to see what is wrong with that object you refer to in order to find out more. It looks like you are using COM? How would I add an error handler, like I said I'm still fairly new to this! Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 (edited) look here Apparently, if you use the SAP UDF it has one called _SAPErrorHandlerRegister and can lead to results like he got... maybe it's greyed out not available yet... etc err.number is: -2147352567 err.windescription: err.description is: The menu item is disabled. err.source is: SAP Frontend Server err.helpfile is: C:\Programmi\SAP\FrontEnd\sapgui\sapfront.HLP err.helpcontext is: 393215 err.lastdllerror is: 0 err.scriptline is: 342 err.retcode is: 623 Edited June 28, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 (edited) You can use the UDF alongside your generated script too from what I have read in this forum. update, I looked at SAP.au3 and it does not have that handler. Edited June 28, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 so, from that link, if you do this, you should be able to build one $oMyError = ObjEvent("AutoIt.Error","SAP_Error") Func SAP_Error() MsgBox(0, "SAP", "Can't find the specified menu item!") Endfunc My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
automationguy128 Posted June 28, 2018 Author Share Posted June 28, 2018 2 hours ago, Earthshine said: so, from that link, if you do this, you should be able to build one $oMyError = ObjEvent("AutoIt.Error","SAP_Error") Func SAP_Error() MsgBox(0, "SAP", "Can't find the specified menu item!") Endfunc Managed to get it working, thanks a lot! Earthshine 1 Link to comment Share on other sites More sharing options...
Earthshine Posted June 28, 2018 Share Posted June 28, 2018 (edited) @automationguy128 can you share with us how? for others with similar issues Edited June 28, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
automationguy128 Posted June 29, 2018 Author Share Posted June 29, 2018 ;Continued $session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellRow = 4 $session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows = "4" $session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell $session.findById("wnd[0]/tbar[1]/btn[8]").press sleep(15000) $oMyError = ObjEvent("AutoIt.Error","SAP_Error") Func SAP_Error() $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").pressToolbarContextButton ("&MB_VIEW") $session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell").selectContextMenuItem ("&PRINT_BACK_PREVIEW") $session.findById("wnd[0]/mbar/menu[4]/menu[5]/menu[2]/menu[2]").select ;MsgBox(0, "SAP", "Can't find the specified menu item!") Endfunc $session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").select $session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[1,0]").setFocus ;Continued Here you go! Earthshine 1 Link to comment Share on other sites More sharing options...
Earthshine Posted June 29, 2018 Share Posted June 29, 2018 wow, you used the error handler to do your business? nice one on you. My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now