Hi All. I am back with this new post. Many times this
question has been asked on many forums. However, there are hardly any suitable/complete
answer. One of my reader has requested me to post on this topic. I took some
time out of my schedule and am posting my findings. I hope you find it useful.
Below code is a sample code which I have written. This uses a descriptive programming which means it will work for any SAPGuiTree. No need to bother about objects. This code
searches for a particular node and
activates it. This function also gives the total node count and navigates through
each one of them. Please leave your comment if you find it useful.
'************************************************************************
'Function Name: SAP_Search_And_Activate_Node_In_SAPGuiTree
'Description: Searches and activates a node in SAPGuiTree using the search node text parameter.
'Parameter: Search node text, enter a value that you want to search,
' For example if you are looking for Outbound
delivery no, you can enter the full text or just delivery for search key
'Return Value: Returns True/False
'Author: Ankesh
'Creation Date:
'**********************************************************************
Function SAP_Search_And_Activate_Node_In_SAPGuiTree(strSearchNodeText)
'get all the objects of SAPGUITree
'Descriptive programming has been used
Set ObjSAPGuiTree =
SAPGuiSession("micclass:=SAPGuiSession").SAPGuiWindow("micclass:=SAPGuiWindow").SAPGuiTree("micclass:=SAPGuiTree").Object
'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
blnFlag=False
'Iterate through the nodes of the tree
For i = 0 to intNodeCount-1
'Get the node text
strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))
'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
'Chk the flag and return values to function
If blnFlag Then
SAP_Search_And_Activate_Node_In_SAPGuiTree=True
Else
SAP_Search_And_Activate_Node_In_SAPGuiTree=False
End If
'Release the objects
Set ObjKeyValues=Nothing
Set ObjSAPGuiTree=Nothing
End Function
To get the hierarchy of the node being searched,
ReplyDeleteyou can keep adding the node text in an array/string. Something like
strNodeHierarchy=""
strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))
if strNodeHierarchy="" Then
strNodeHierarchy=strNodeText
Else
strNodeHierarchy=strNodeHierarchy&";"& strNodeText
End IF
If a macth is found for the node that you are looking for, strNodeHierarchy will hold the hierarchy for the node.
Thanks.
Ankesh,
ReplyDeleteI am trying the following code to get all the hierarchy of the said treenode,but i am able to only getting one above node,i am unable to get whole hierarchy,please look at the below code and help me.
Dim Nodename
Set GuiTree = SAPGuiSession("program:=SAPLSMTR_NAVIGATION").SAPGuiWindow("transaction:=SESSION_MANAGER").SAPGuiTree("treetype:=SapListTree").Object
Set Keyvalues = GuiTree.GetAllNodeKeys
objcount = Keyvalues.Count
For i = 1 to (objcount-1)
Nodename = GuiTree.GetNodeTextByKey(Keyvalues(i))
If Nodename="Purchase Requisitions" Then
j=i-1
print Keyvalues(j)
print GuiTree.GetNodeTextByKey(Keyvalues(j))
End If
Next
@Venkat,
ReplyDeleteThe reason why you are getting only one above hierarchy is because of the wrong code.Your below code if checking for a match.
If Nodename="Purchase Requisitions" Then
j=i-1
print Keyvalues(j)
print GuiTree.GetNodeTextByKey(Keyvalues(j))
End IF
** Now suppose that the matching node was found at i=5. so when you do J=i-1, j is 4 now. So when you will try to get the node name, it will obviously return the node just above the matching node not the whole hierarchy.
;********
To get the whole hierarchy, you need to navigate through each node and keep storing the node text in any variable till a macth is found.
Try using the below code. Add this code hust above the if block where you are comparing to check for a macth.
strNodeHierarchy="" 'take a empty variable
strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))
if strNodeHierarchy="" Then
strNodeHierarchy=strNodeText
Else
strNodeHierarchy=strNodeHierarchy&";"& strNodeText
End If
If Instr(strNodeText,strSearchNodeText)>0 Then
End IF
'****
strNodeHierarchy holds the node hierarchy.
Let me know if you need more help.
Ankesh,
ReplyDeleteI tried still i am unable to get thru, please help
Dim Nodename
Dim ParentName
Set GuiTree = SAPGuiSession("program:=SAPLSMTR_NAVIGATION").SAPGuiWindow("transaction:=SESSION_MANAGER").SAPGuiTree("treetype:=SapListTree").Object
Set Keyvalues = GuiTree.GetAllNodeKeys
objcount = Keyvalues.Count
'msgbox objcount
For i = 1 to (objcount-1)
'print Keyvalues(i)
Nodename = GuiTree.GetNodeTextByKey(Keyvalues(i))
strNodeHierarchy=" " 'take a empty variable
strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))
if strNodeHierarchy="" Then
strNodeHierarchy=strNodeText
Else
strNodeHierarchy=strNodeHierarchy&";"& strNodeText
End If
If Instr(strNodeText,strSearchNodeText)>0 Then
End IF
If Nodename="CACS_BDTI_SEL_2 - Change" then
print ParentName
j=i-1
'print Keyvalues(j)
'print GuiTree.GetNodeTextByKey(Keyvalues(j))
End If
Next
@Venkat,
ReplyDeleteCode is fine. just use
strNodeHierarchy="" instead of
strNodeHierarchy=" "
You will get the text. Let me know what you are geting as output. It would be easier for me to understand.
i am still getting error, i changed the code
ReplyDeletestrNodeHierarchy="" instead of
strNodeHierarchy=" "
Please help with below code,run the code at ur end just change the parameter, and let me know soon possible
Dim Nodename
Dim ParentName
Set GuiTree = SAPGuiSession("program:=SAPLSMTR_NAVIGATION").SAPGuiWindow("transaction:=SESSION_MANAGER").SAPGuiTree("treetype:=SapListTree").Object
Set Keyvalues = GuiTree.GetAllNodeKeys
objcount = Keyvalues.Count
'msgbox objcount
For i = 1 to (objcount-1)
'print Keyvalues(i)
Nodename = GuiTree.GetNodeTextByKey(Keyvalues(i))
strNodeHierarchy=" " 'take a empty variable
strNodeText=ObjSAPGuiTree.GetNodeTextByKey(ObjKeyValues(i))
if strNodeHierarchy=" " Then
strNodeHierarchy=strNodeText
Else
strNodeHierarchy=strNodeHierarchy&";"& strNodeText
End If
If Instr(strNodeText,strSearchNodeText)>0 Then
End IF
If Nodename="CACS_BDTI_SEL_2 - Change" then
print ParentName
j=i-1
'print Keyvalues(j)
'print GuiTree.GetNodeTextByKey(Keyvalues(j))
End If
Next
hi ankesh,
ReplyDeletethanks for the wonderful idea for usage of SAPGuiTree object methods. I wonder if you can share any document/ebook on the same, like using methods of SAP objects. I've started learning now. Just curious to dive deep into this topic.
thanks,
madhan
Hi Ankesh,
ReplyDeleteI would like to capture events (as callbacks from the Tree Control) from a SAP Tree Control, when a user clicks on a Node or sub node in the tree hierarchy. I am using SAPGUI scripting. However GuiTree does not support events. Can you suggest an approach (or code snippet) to do this?
Thanks
Hello,
ReplyDeleteI am facing an issue with SAPGUITree. I need to fetch value from 2nd column in the tree. Can anyone help me regarding this. By using the Selectnode ,SelectItem method we can fetch value from 1st COlumn of the SAPGUITree. But did not find any method or any way to fetch value rom 2nd column.
Thanks
Ashwini
Hello Aashwini,
DeleteI hope you have received a solution for this. We also stuck with the same issue now. can you please help us with this solution.
rajendra.chidara@gmail.com
I had an issue with SAPGUItree. I wanted to activate and click a value from the SAPGUI tree. I used your code above but received a general error on the following line:
ReplyDeleteSet ObjSAPGuiTree = SAPGuiSession("micclass:=SAPGuiSession").SAPGuiWindow("micclass:=SAPGuiWindow").SAPGuiTree("micclass:=SAPGuiTree").Object
Thanks
UFT User
Below is the lines of code for SAP "Purchase Requisition" form, where I am trying to enter the field values through descriptive programming, but this code is not working. Can any help me on this would be appreciated.
ReplyDeleteSAPGuiSession("program:=SAPLMEGUI").SAPGuiWindow("program:=SAPLMEGUI" , "transaction:=ME51N" , "screennumber:=14").SAPGuiGrid("micclass:=SAPGuiGrid", "guicomponenttype:=201").ClickCell 1,"Status"
SAPGuiSession("program:=SAPLMEGUI").SAPGuiWindow("program:=SAPLMEGUI" , "transaction:=ME51N" , "screennumber:=14").SAPGuiGrid("micclass:=SAPGuiGrid", "guicomponenttype:=201").Input "Action1.GridViewCtrl"
How to Activate a SAP tree Item using the Key ?
ReplyDeleteIf I use SelectNode it is not activating the node. It is just selecting the node. If I use DoubleclickNode, No response from the Application.. Can you please help me ?
This comment has been removed by the author.
ReplyDeleteHello Ankesh, how are you doing?
ReplyDeleteHope everything is just fine.
I have a task where i'm using the sap gui tree control, however i'm not being totally successful. The thing is I'm trying to read through a script the SU53 screen. It seems by the results that is like the gui tree control has columns but i'm only reading the first one and not being able to access the others. Do you have any ideas on how can I reach this info, please? Below there is my code:
Public Sub ExecutionCorrectionCycle()
Dim myTreeContainer As GuiTree
Dim totalRows, totalCol As Long
'Botões Operados
Dim otherUserbtn, confirmBtn As GuiButton
'Caixa de Texto da SU53 para outros usuários
Dim userIdEntry As GuiCTextField
Dim thisContentKey As GuiCollection
Dim i As Long
Dim thisText() As String
'Iniciando transação
SAPSession.StartTransaction("SU53")
'Pressionando o Botão para outros usuários
otherUserbtn = SAPSession.FindById("wnd[0]/tbar[1]/btn[5]")
otherUserbtn.Press()
'Entrando com o ID a ser buscado de usuário
userIdEntry = SAPSession.FindById("wnd[1]/usr/ctxtG0010_BNAME")
userIdEntry.Text = "Z_TEST_AUTOM"
'Clicando no botão de confirmação da busca
confirmBtn = SAPSession.FindById("wnd[1]/tbar[0]/btn[8]")
confirmBtn.Press()
'Necessário colocar rotina de validação do retorno de usuários não existentes aqui
myTreeContainer = SAPSession.FindById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell")
'SU53ToolBar = SAPSession.ActiveWindow.FindById("/tbar[1]")
thisContentKey = myTreeContainer.GetAllNodeKeys
totalRows = thisContentKey.Count
'Tentar de acordo com o post abaixo
'http://automatingsap.blogspot.com.br/2012/10/working-with-sapguitree-search-and.html
'No momento estou lendo só a primeira coluna. Preciso das demais
For i = 0 To totalRows - 1
ReDim Preserve thisText(i)
thisText(i) = myTreeContainer.GetNodeTextByKey(thisContentKey.Item(i).ToString)
Next i
End Sub
Thanks in advance.
Best Regards,
Caio
The previously mentioned matter is anything but difficult to comprehend as well as clarify. Indeed, even I can expound subject of this article now effortlessly on the grounds that I it is straightforward for me. Truly an inventive master aptitude controlled by creator. busca software
ReplyDeleteHi Ankesh,
ReplyDeletehow to capture status(red, green, amber) after expanding the node in sapguitree?
TIA
Keshav
Hi Mishra,
DeleteDid you found the way? Can you please share it here?
Thank you in advance.
P.S. In the past I used images.
But I think that it's not the best way to use the UFT Insight object(s) for the checks. It would be so much better to check some property value (versus image).
BR
Serg