Hello everyone,
I have recorded a certain script to do a repetitive task in SAP such as entering string data in a specific field. My problem is that when a specified object cannot be modified, I get an error message. Here is the script and in yellow is where the bug is:
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
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[0]/shell/shellcont[0]/shell").pressButton "OPEN"
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PROJ_EXT").text = "ING-163723"
session.findById("wnd[1]/usr/ctxtCNPB_W_ADD_OBJ_DYN-PROJ_EXT").caretPosition = 10
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3998/tabsPTABSCR/tabp+CUD").select
session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3998/tabsPTABSCR/tabp+CUD/ssubSUBSCR2:SAPLCJWB:1216/ssubCUSTSCR1:SAPLXCN1:0600/txtPROJ-ZZ_COMMENT_SUIVI").text = "Bourgogne"
session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3998/tabsPTABSCR/tabp+CUD/ssubSUBSCR2:SAPLCJWB:1216/ssubCUSTSCR1:SAPLXCN1:0600/txtPROJ-ZZ_COMMENT_SUIVI").setFocus
session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3998/tabsPTABSCR/tabp+CUD/ssubSUBSCR2:SAPLCJWB:1216/ssubCUSTSCR1:SAPLXCN1:0600/txtPROJ-ZZ_COMMENT_SUIVI").caretPosition = 5
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[0]/shellcont/shellcont/shell/shellcont[1]/shell/shellcont[1]/shell").topNode = " 23"
I get this error message : "The method got an invalid argument.-"
It is of course invalid because for this specified project this object (field is grey) cannot be modified but I have a lot of these same script lined up in the same .vbs. When this error occurs, the script stops without completing the whole task.
I want to know if I can write a condition so that if I can modify the object, the script goes on, if not nothing hapens and it goes to the next task.
I was thinking:
If session.findById("wnd[0]/usr/subDETAIL_AREA:SAPLCNPB_M:1010/subVIEW_AREA:SAPLCJWB:3998/tabsPTABSCR/tabp+CUD").select then
...
endif
This dosen't work. I am beginning in this language so your help would be greatly appreciated!
Thank you.
(do something here)
else
(do something else)
end if