cancel
Showing results for 
Search instead for 
Did you mean: 

Get Material and Date from GuiTree using VBScript

Former Member
0 Kudos

I would like to fetch Material and Date from GuiTree using VBScript.

Below is my code that fetches ConRecNo (Ex:0000006669, 0000045082 etc.,)


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

strSearchNodeText = "0000045082"

Set aw = session.activeWindow()

Set ObjSAPGuiTree = aw.FindById("wnd[1]/usr/cntlTREE1/shellcont/shell/shellcont[1]/shell[1]")

    'Get the node keys , a key is a number/position in the

    'A key value starts from 1.

    Set ObjKeyValues = ObjSAPGuiTree.GetAllNodeKeys

    'get the total count

    ''This count indicates the number of items/nodes in the Tree

    intNodeCount = ObjKeyValues.Count

    msgbox intNodeCount

    blnFlag=False

    'Iterate through the nodes of the tree

    For i = 0 to intNodeCount-1

        'Get the node text

        strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))

'       strNodeText=ObjSAPGuiTree.getCellValue(i,"Material")

        msgbox strNodeText

        'Check if the match was found for the key that you are looking for

        'if yes then activate the item

        If Instr(strNodeText,strSearchNodeText)>0 Then

            'Select the node and double click on it

            'This is equivalent to ActivateItem

            ObjSAPGuiTree.SelectNode ObjKeyValues(i)

            ObjSAPGuiTree.DoubleClickNode ObjKeyValues(i)

            blnFlag=True 'set a flag to indicate the macth was found

            Exit For

        End If

   

    Next

    'Release the objects

     msgbox intNodeCount

    Set ObjKeyValues=Nothing

    Set ObjSAPGuiTree=Nothing

' myText = session.findById("wnd[1]/usr/cntlTREE1/shellcont/shell/shellcont[1]/shell[1]").getNodeTextByPath("1\1\4")

' msgbox myText

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


Accepted Solutions (0)

Answers (2)

Answers (2)

script_man
Active Contributor
0 Kudos

Hi sap krazy,

before a long time, I had a similar problem. I solved it like follows:

. . .

  For i = 0 to intNodeCount-1

        'Get the node text

        strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))

'       strNodeText=ObjSAPGuiTree.getCellValue(i,"Material")

        msgbox strNodeText

        strNodeText_Material = ObjSAPGuiTree.getItemText(CStr(ObjKeyValues(i)),"C          3")

        'Check if the match was found for the key that you are looking for

        'if yes then activate the item

        If Instr(strNodeText,strSearchNodeText)>0 Then

            'Select the node and double click on it

            'This is equivalent to ActivateItem

            ObjSAPGuiTree.SelectNode ObjKeyValues(i)

            ObjSAPGuiTree.DoubleClickNode ObjKeyValues(i)

            blnFlag=True 'set a flag to indicate the macth was found

            Exit For

        End If

 

    Next

. . .

The parameter ItemName = "C          3" I took from the recorded script:

. . .

session.findById("wnd[0]/usr/cntlCNTL_CONTAINER/shellcont/shell/shellcont[0]/shell/shellcont[1]/shell[1]").selectItem "         11","C          3"

session.findById("wnd[0]/usr/cntlCNTL_CONTAINER/shellcont/shell/shellcont[0]/shell/shellcont[1]/shell[1]").ensureVisibleHorizontalItem "         11","C          3"

session.findById("wnd[0]/usr/cntlCNTL_CONTAINER/shellcont/shell/shellcont[0]/shell/shellcont[1]/shell[1]").itemContextMenu "         11","C          3"

session.findById("wnd[0]/usr/cntlCNTL_CONTAINER/shellcont/shell/shellcont[0]/shell/shellcont[1]/shell[1]").selectContextMenuItem "&FIND"

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

It places the cursor on the cell with the material and press the right mouse button. Then select from the context menu the Find command and then pressing Cancel. Here, the upper script originated. Then you would only have to figure out in your script how is your column name for material. The date would have to work on the same principle.


Regards,

ScriptMan

holger_khn
Contributor
0 Kudos

Hello.

May I miss your question. What is your issue right now?

Former Member
0 Kudos

Hi Holger,

Thanks for taking time to read my query. I need your help in coding VBScript.

I would like to fetch Material and Date information from GuiTree. Using method GuiTree type method I figured its a 2 (Column tree). Please refer to picture attached. I'm can fetch condition record number (example:  0000004574, 0000045082 etc.,) but not corresponding material and date information.

Your help is much appreciated!!

holger_khn
Contributor
0 Kudos

Hello. What happen if you doubleclick on a line?

Does it open a child gui table below?

Former Member
0 Kudos

No, Double click has no effect, no popup or new screen. It just stays on same screen.

Thanks!

holger_khn
Contributor
0 Kudos

Unfortunately I can´t discover this object in my System as we do not have any Setup/masterdata for this Transaction QC03.

As you can see on my Picture we have this GUITREE similar as ALV. First column can be read as nodekey. Subsequent data will appear as child_gui after doubleclick and all columns can be read.