Jump to content

Unable to select SAP lower toolbar options from scripting


Recommended Posts

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"

Capture1.PNG

Capture2.PNG

Link to comment
Share on other sites

Instead of pictures, post your code.

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 Gude
How 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

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

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 Gude
How 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

#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

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

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

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

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

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

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

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

;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!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...