Skip to Content

How to detect last parent node and fetch data from its child node with VBA Script

Dear fellow users,

I have just encountered a case that has made me grind to a halt.

I want to drill data from a custom SAP tcode. What I cannot get on: on a sub-subscreen, there is a log list with items. I want to pick the last one from the list, but cannot get either the row number or the cell content to locate the desired cell and double click on.

my code:

Set GRID1 = session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell")
GRID1Rows = GRID1.RowCount - 1

For i = 0 To GRID1Rows
PONrSAP = GRID1.getcellvalue(i, "EBELN")
GRID1.setCurrentCell i, "SLGREF"
'we get in the process log of the item now.
Set GRID3 = session.findById("wnd[0]/usr/subSUBSCREEN:SAPLSBAL_DISPLAY:0101/cntlSAPLSBAL_DISPLAY_CONTAINER/shellcont/shell/shellcont[0]/shell")

'here is  the problem. I only can hard code the item from script record'ing, but
'if there are several log results listed, I have no method to find the 'last item in the list.
'this is the first from the list, which is OK if item has been processed once only:
GRID3.selectItem "1         1", "101"
'this is an example of the item processed more then once, so this is th'e actual process result I want to double click on:
'GRID3.selectItem "1         4", "101"
'I continue with line nr 1, as you can see on the screenshot.
GRID3.ensureVisibleHorizontalItem "1         1", "101"
GRID3.doubleClickItem "1         1", "101"
'from this point, all is fine.

'(some more code here)

next i

As you can see, I was able to apply the RowCount method in GRID1.RowCount. But in case of GRID3, it returns an error message: 'Object does not support this property or method' (I already removed it from the code).

Thank you All for any hint in advance!


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Mar 08, 2018 at 09:36 AM

    Hi Laszlo,

    the described issue interested me personally and therefore I offer here a suggestion that could be tested.

    The Object GRID3 is not a grid by nature but a tree. ;-)

    . . .
    'we get in the process log of the item now.
    Set Node_Object = session.findById("wnd[0]/usr/subSUBSCREEN:SAPLSBAL_DISPLAY:0101/cntlSAPLSBAL_DISPLAY_CONTAINER/shellcont/shell/shellcont[0]/shell")
    Set nodeCol = Node_Object.getNodesCol
    For i = 0 To nodeCol.Count - 1
      key = nodeCol.elementAt(CInt(i))            'returns the key of the nodes
    Node_Object.selectItem "1" & right(space(9) & cstr(key),10), "101"
    Node_Object.ensureVisibleHorizontalItem "1" & right(space(9) & cstr(key),10), "101"
    Node_Object.doubleClickItem "1" & right(space(9) & cstr(key),10), "101"
    '(some more code here)
    next i



    Add comment
    10|10000 characters needed characters exceeded

    • Hi ScriptMan,

      great piece of work, thank you so much! I adjusted it to catch only the last node (as by the nature of the log report, I always need only the last one as the others are historic logs from other failed jobs), it perfectly fits my logic and serves the purpose.

      This site was also a great help to understand the logic, I have found it in another comment of yours just now. Thank you for sharing, helped me so much catch the logic - I re-post it here on your credit NOT on mine, just as a useful reference of other users struggling with this special topic too:

      And yes, as for GRID3 - absolutely right, my bad :-) Already renamed to a more matching object name.

      Have a great day, Laszlo