How to select menu from SAP GUI menu bar - sap-gui

I'm trying to get to work the first line in the code. It is recorded with SAP GUI recording. I tried to check what it shows as text when chopping the code in pieces. The last line shows the correct option "Close" but it does not work in the code. How others have succeeded to choose sub options from menu bar? The correct path is Functions->Restrict processing->Close.
session.findById("wnd[0]/mbar/menu[1]/menu[8]/menu[6]").select 'does not work
MsgBox CStr(session.findById("wnd[0]/mbar").Children.Count) 'shows 8
MsgBox session.findById("wnd[0]/mbar/menu[1]").text 'shows function
MsgBox Cstr(session.findById("wnd[0]/mbar/menu[1]").Children.Count)'shows 0?
MsgBox session.findById("wnd[0]/mbar/menu[1]/menu[8]").text 'does not work
MsgBox session.findById("wnd[0]/mbar/menu[1]/menu[8]/menu[6]").text'shows close

Related

SAP GUI script for information window

I need to get this window to click on the continue button if it pops out when no data is changed and continue with the next cell
You need to use something like this...
Note: you need to change this "wnd[1]/usr/tblSAPLV14ATCTRL_D0102" with the script you recorded.
If Not session.findById("wnd[1]/usr/tblSAPLV14ATCTRL_D0102", False) Is Nothing Then
session.findById("wnd[1]/tbar[0]/btn[24]").press
End If

How to Click a Link on a IE webpage?

I want to open a button named 'Open' in IE window using VBScript. Source code is like this:
<a title="Devtems Life Menu" href="javascript:OpenOryx('cboClone');">Open</a>
Before I start answering the question, I just want to say that I am by no means an expert at VBScript. My knowledge is based off a lot of messing around with it during weekends and a bit of read the documentation. There may be better ways of doing things, but this works for me.
My recommendation is if you have access to the html, add an attribute to your link so it looks something like this:
<a title="Devtems Life Menu" href="javascript:OpenOryx('cboClone');" id="openMenu">Open</a>
Then you can easily reference it in your code. If you can't access the html, then you may have to use a more roundabout way of checking the contents of each link. The actual syntax is described below in a little script I constructed. It firstly loads w3schools.com, then clicks on the references tab. This uses ie.document.getElementById(arg). Notice that the references navigation panel opens. After that it will prompt you to click the ok button to continue. It will then load google.com, and look through all the <a> tags. If it contains Open it clicks on it. You can use the same syntax, except different details for your script.
' Create the ie object
set ie = createobject("internetexplorer.application")
' Navigate to wherever you want
ie.navigate("http://www.w3schools.com/")
ie.Visible = true
' Call the subroutine we define below
waitForPage(ie)
' Get link by id
' This is a one liner, and I personally think is better than the method below
' first of all you get the tag you want by id
' then you click it
ie.document.getElementById("navbtn_references").click()
' call ie.document.parentWindow.execScript("w3_open_nav('references')", "JavaScript")
' could also be written as:
'set buttonElement = ie.document.getElementById("navbtn_references")
'buttonElement.click()
MsgBox("Click ok to continue to google.")
' Load google
ie.navigate("https://google.com/")
' And wait for it to load
waitForPage(ie)
' Click on a link by attribute (same technique can be used for name etc)
' Get all elements with tag input
set linkElements = ie.document.getElementsByTagName("a")
' Then loop through them
for each possibleElement in linkElements
' If it has a certain name..
if possibleElement.innerHtml = "About" then ' You could use If possibleElement.getAttribute("name") = "foo" Then or possibleElement.getAttribute("class") = "bar"
' Click it!
possibleElement.click()
end if
next
' Subroutine to wait for internet explorer to load a page
sub waitForPage(ie)
do
WScript.Sleep(100)
loop while ie.ReadyState < 4
end sub
Another method is rather than actually finding and clicking on the link, you simply run the script that is run when a user normally clicks on a link. In your case, it could mean running javascript:OpenOryx('cboClone'); directly. Here is how to run javascript code in VBScrpt:
call ie.document.parentWindow.execScript("javascript:OpenOryx('cboClone');", "JavaScript")
I hope that at least one of these methods helps you in writing your script.

how do you make something happen if a button is pressed in applescript

I am trying to make an app in applescript where if you try to turn the volume down the volume is set to 16. I am still a beginner and i was wondering if there is a 'if buttonpress' sort of command. Thanks!
Assuming I'm understanding you, this is the basic idea:
set button_returned to button returned of (display dialog "hi")
if button_returned is "OK" then
#do something
end if
You put up a dialog, then check for the name of the button clicked, and if the name matches whichever button you're checking for, then "do something".

How check if exists the field? SAP GUI Scripting

How check if exists the field?
I tried it:
If session.findById("wnd[1]").setFocus Then
you can try e.g. the following:
on error resume next
session.findById("wnd[1]").setfocus
if err.number = 0 then
msgbox "The SAP GUI element exists."
else
msgbox "The SAP GUI element does not exist."
end if
on error goto 0
Regards,
ScriptMan
To avoid using error handling you can use:
If Not session.findById("wnd[1]", False) Is Nothing Then
session.findById("wnd[1]").setFocus
End If
The key here is the second parameter in FindById which determines if it raises an error or not if the field or any object in SAP exists. If it is set to False there is no error raised and the object is set to Nothing which you can check as in my code.
If the question is how to see if there's a second window: wnd[1]
This should work:
Sub test()
If session.Children.Count = 2 then
'your code goes here
End If
End Sub
It also has the advantage that it doesn't need to use error handling to work,
so another type of error could occur and still be handled.

Access 2010 : Queries not working when executed as Sub-Forms

i have created forms which use queries to manipulate and show data, these queries have [criteria] which is taken from a combo box \ text field in the form.
it runs perfectly when i execute the form alone, however when executing it from the MainNavigationForm (tabbed navigation style) it pops-up the "enter criteria" dialog that you usually get when you specify a criteria without any source - like empty brackets [].
i am posting the VB code behind both forms, both behave the same way, and pop the dialog for criteria when launching them from the main navigation form, the first form has more code because it updates the query and values in another combo box based on the value of the first combo box. the second form just runs the query again when value in the combo box is changed.
thank you for your help.
Option Compare Database
Private Sub Command23_Click()
DoCmd.OpenQuery "QryMaintProgPlan", acViewNormal
End Sub
Private Sub id_combo_AfterUpdate()
DoCmd.ShowAllRecords
DoCmd.FindRecord Me!id_combo
Me.maint_combo.Requery
Me.emp_combo.Requery
End Sub
Private Sub maint_combo_AfterUpdate()
Me.emp_combo.Requery
Me.EmployeeID = emp_combo.ItemData(0)
End Sub
2nd form :
Option Compare Database
Private Sub btn_requery_Click()
DoCmd.ShowAllRecords
End Sub
Ok, i have found the answer, i was supposed to use the adress of the navigationSubform in the query criteria because once i launched it from the navigationForm it no longer used the same adress. [Forms]![frmMainNavigation]![NavigationSubform]![id_combo] is the correct one
instead of [Forms]![frmMaintProgPlan]![id_combo].

Resources