cancel
Showing results for 
Search instead for 
Did you mean: 

Loop in VBS script recording

Former Member
0 Kudos

Hi

I am new to both SCN and scripting and am in need of some guidance.

I have a SQ01/2 query, which gives the following results:

I have then recorded the following script:

This script works fine, but I need it to loop to the next selectedRow (which is the Delivery column) and then continue looping until there are no more lines.

I would really appreciate it if someone could help me.

Many Thanks

Smon

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

I have one final problem (sorry).  My script now works fine when I have single line entries in the "Delivery" column (VBELN); whoever, when there are duplicate entries, which I do need to see, the loop fails as it is trying to execute the script on a delivery that has already had the lines deleted (as per the recording) eg:

The script now looks like this:

If Not IsObject(application) Then

   Set SapGuiAuto  = GetObject("SAPGUI")

   Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then

   Set connection = application.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 application, "on"

End If

session.findById("wnd[0]").maximize

set GRID = session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell")

myRow = 0

if GRID.rowCount >= 1 then

  do

   GRID.selectedRows = cstr(myRow)

   GRID.setCurrentCell myRow,"VBELN"

   GRID.doubleClickCurrentCell

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\05").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\05/ssub/2/3/sub/2/3/3/btn[1]").press

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssub/2/3/sub/2/3/3/btn[4]").press

session.findById("wnd[1]/usr/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[11]").press

   myRow = myRow + 1

   if myRow >= GRID.rowCount  then exit do

   GRID.firstVisibleRow =   myRow

   GRID.selectedRows = cstr(myRow)

  loop

end if

Is there any way that the duplicate lines can be skipped, or that the loop resumes after an error?

Kind Regards

Simon

script_man
Active Contributor
0 Kudos

Hi Simon,

One could try e.g. the following:

. . .

session.findById("wnd[0]").maximize

set GRID = session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell")

myRow = 0

if GRID.rowCount >= 1 then

  do

   GRID.selectedRows = cstr(myRow)

   GRID.setCurrentCell myRow,"VBELN"

   myVBELN = GRID.getcellvalue (myRow,"VBELN")

   GRID.doubleClickCurrentCell

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\05").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\05/ssub/2/3/sub/2/3/3/btn[1]").press

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01").select

session.findById("wnd[0]/usr/tabsTAXI_TABSTRIP_OVERVIEW/tabpT\01/ssub/2/3/sub/2/3/3/btn[4]").press

session.findById("wnd[1]/usr/btn[0]").press

session.findById("wnd[0]/tbar[0]/btn[11]").press

   do 

    myRow = myRow + 1

    if myRow >= GRID.rowCount  then exit do

    GRID.firstVisibleRow =   myRow

    GRID.selectedRows = cstr(myRow)

    if myVBELN <> GRID.getcellvalue (myRow,"VBELN") then exit do

   loop

   if myRow >= GRID.rowCount  then exit do

  loop

end if

If your problem is solved, please mark this question as answered.

Regards,

ScriptMan

Former Member
0 Kudos

Thank you ScriptMan, everything works perfectly - I really appreciate your help.

Kind Regards

Simon

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Script Man

Thank you so much for the quick reply.  It's not quite working yet as when it loops, the script is trying to double click on the original cell, rather than stepping to the next cell...you've certainly pointed me in the right direction though!

Kind Regards

Simon

script_man
Active Contributor
0 Kudos

Hi Simon,

Unfortunately, I do not know what name has the current cell. This name you need, you can find by Sort the corresponding column with the Script Recorder.

for example:

. . 

session.findById("wnd[0]").maximize

set GRID = session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell")
myRow = 0

if GRID.rowCount >= 1 then
  do
   GRID.selectedRows = cstr(myRow) 

   GRID.setCurrentCell myRow,"myColumn_Name"
   GRID.doubleClickCurrentCell

   'Here is the rest of your script after the command with ". doubleClickCurrentCell" to the end.


   myRow = myRow + 1
   if myRow >= GRID.rowCount  then exit do
   GRID.firstVisibleRow =   myRow

   GRID.selectedRows = cstr(myRow)

  loop
end if

Regards,

ScriptMan

Former Member
0 Kudos

Hi ScriptMan

This is brilliant...thank you so much for your help!

Kind Regards

Simon

script_man
Active Contributor
0 Kudos

Hi Simon,

welcome to the forum. You could try the following in the further tests.

for example:

. . .

session.findById("wnd[0]").maximize

set GRID = session.findById("wnd[0]/usr/cntlCONTAINER/shellcont/shell")
myRow = 0

if GRID.rowCount >= 1 then
  do
   GRID.selectedRows = cstr(myRow)  
   GRID.doubleClickCurrentCell

   'Here is the rest of your script after the command with ". doubleClickCurrentCell" to the end.


   myRow = myRow + 1
   if myRow >= GRID.rowCount  then exit do
   GRID.firstVisibleRow =   myRow

   GRID.selectedRows = cstr(myRow)

  loop
end if

Regards,

ScriptMan