Reputation: 1906
I'm trying to automate T-Code-VA03.
I enter the PO number in PO number text box and press F8
.
This prompts a window which contains multiple rows of labels.
My requirement is, I want to select the one with latest date. I tried to record the script for it and below the code.
session.findById("wnd[0]/usr/txtRV45S-BSTNK").text = "123456789"
session.findById("wnd[0]/usr/txtRV45S-BSTNK").setFocus
session.findById("wnd[0]/usr/txtRV45S-BSTNK").caretPosition = 8
session.findById("wnd[0]").sendVKey 8
session.findById("wnd[1]/usr/lbl[49,6]").setFocus
session.findById("wnd[1]/usr/lbl[49,6]").caretPosition = 0
I can see there are labels with indexes. How can I iterate through whole window and take the focus to row with latest date?
Upvotes: 0
Views: 7700
Reputation: 1625
With VB script you could try the following:
. . .
session.findById("wnd[0]").sendVKey 8
for i = 6 to 99
on error resume next
session.findById("wnd[1]/usr/lbl[49," & cstr(i) & "]").setFocus
if err.number <> 0 then Exit for
on error goto 0
session.findById("wnd[1]/usr/lbl[49," & cstr(i) & "]").caretPosition = 0
next
Regards, ScriptMan
Upvotes: 2
Reputation: 43595
If you really need to do something like iterating through window and taking the focus to row with latest date, do not do it with VBA, because you may get into lots of problems.
Having said the one above, try with sendkeys https://msdn.microsoft.com/en-us/vba/excel-vba/articles/application-sendkeys-method-excel
and send TAB. Then make a code searching for "Item" in your form. After this, send tab 8 times to go to the PO Date
. Write the date on a list. Send TAB again 11 times to the next date. Write it on a list. And so, until there are no more dates.
Anyhow, as I mentioned, this is not a great solution. The best way is simply to ask the DB Admin for read-only access to the DB or a customized view. With it, you can make a robust solution, which reads the latest date.
Upvotes: 1