preload

GP/QTP Automation: GUI Capture script for Dexterity Window

Posted by Albert Gareev on Oct 12, 2009 | Categories: Great PlainsSource code


A script capturing Dexterity objects (both GUI and non-GUI) contained within the window. Great Plains application is required to be up with the particular window invoked and activated.

All related posts: Reference Page – GP/QTP Automation  

Programming language and tool: VBScript / QTP. 

The script produces an output as XML file with the structure similar to QTP object repository.

Used resources:

GPHandle object class

GetDexActiveWindow macro.

Dynamics.Application classes.

Service Functions – XML (QTP, VBScript)

Library functions


Public Function GP_InitCOM()
   Dim boolRC

 boolRC = GPHandle.InitWrapper(<path to your VBA macro Excel file>)
 If Not boolRC Then
  GP_InitCOM = FALSE
  Exit Function
 End If

 GPHandle.SetGPHook()

 GP_InitCOM = TRUE
End Function

Public Function GP_CloseCOM()
 GPHandle.ReleaseGPHook()
 GPHandle.CloseWrapper()
End Function

 

The script (put in a separate QTP Action)


Option Explicit
'Purpose: Capture and Map GUI of current (active) GP Dexterity Window into XML file
'Requirements: GP App started, required window is brought up
'DexWrapper.xls is properly set up
'Output: <window name>.xml

Dim boolRC
Dim objWindow, objWndField
Dim objRecord
Dim sGPMapXML
Dim FieldIter
Dim objGPMapXML, objRoot, objFormMapXML, objWndMapXML, objFldMapXML
Dim objDesc, objProperty

boolRC = GP_InitCOM()
If Not boolRC Then
 ExitTest()
End If

GPHandle.GPApp.Activate()

GPHandle.XLHandle.Run("GetDexActiveWindow")

Set objRecord = GPHandle.RetrieveParameters()

Set objWindow = GPHandle.GetDexWindowByName(objRecord.Item("Var1"), objRecord.Item("Var2"))
If objWindow is Nothing Then
 ExitTest()
End If

sGPMapXML = "<your output folder here e.g. c:\temp>" & "\" & objRecord.Item("Var4") &".xml"

Set objGPMapXML = XMLUtil.CreateXML("DexGUI")
Set objRoot = objGPMapXML.GetRootElement

'Form
Set objFormMapXML = CreateChildElementByName(objRoot, "Parent", "")
objFormMapXML.AddAttribute "name", objRecord.Item("Var1")
objFormMapXML.AddAttribute "class", "DexForm"
objFormMapXML.AddAttribute "childcount", "1"
Set objDesc = CreateChildElementByName(objFormMapXML, "desc", "")
Set objProperty = CreateChildElementByName(objDesc, "property", "")
objProperty.AddAttribute "name", "dexname"
objProperty.AddAttribute "value", objRecord.Item("Var1")
'Window
Set objWndMapXML = CreateChildElementByName(objFormMapXML, "Parent", "")
objWndMapXML.AddAttribute "name", objRecord.Item("Var2")
objWndMapXML.AddAttribute "class", "DexWindow"
objWndMapXML.AddAttribute "childcount", CStr(objWindow.CountFields())
Set objDesc = CreateChildElementByName(objWndMapXML, "desc", "")
Set objProperty = CreateChildElementByName(objDesc, "property", "")
objProperty.AddAttribute "name", "dexname"
objProperty.AddAttribute "value", objRecord.Item("Var2")

'Map fields
FieldIter = 1
Set objWndField = objWindow.GetFirstWindowField()
Do

 If Not (objWndField is Nothing) Then
  Set objFldMapXML = CreateChildElementByName(objWndMapXML, "Object", "")
  objFldMapXML.AddAttribute "name", objWndField.GetName()
  objFldMapXML.AddAttribute "class", "DexObject"
  Set objDesc = CreateChildElementByName(objFldMapXML, "desc", "")
  Set objProperty = CreateChildElementByName(objDesc, "property", "")
  objProperty.AddAttribute "name", "dexname"
  objProperty.AddAttribute "value", objWndField.GetName()
  Set objProperty = CreateChildElementByName(objDesc, "property", "")
  objProperty.AddAttribute "name", "id"
  objProperty.AddAttribute "value", CStr(objWndField.GetID())
 End If

 FieldIter = FieldIter +1
 Set objWndField = objWindow.GetNextWindowField()

Loop While FieldIter <= objWindow.CountFields()

'Save
objGPMapXML.SaveFile sGPMapXML

GP_CloseCOM()

Set objWindow  = Nothing
Set objWndField = Nothing
Set objGPMapXML = Nothing
Set objRoot = Nothing
Set objFormMapXML = Nothing
Set objWndMapXML = Nothing
Set objFldMapXML = Nothing
ExitAction(TRUE)
  • 2 responses to "GP/QTP Automation: GUI Capture script for Dexterity Window"

  • Tracy Lilyblade
    1st January 2010 at 14:32

    Happy New Years!! To my favorite blog, hopefully no tactical body armor is required with all those fools blasting their automatic weapons along busy streets.

  • Austin
    9th February 2010 at 9:37

    Albert.

    Thank you for a neat code! I use GUI Capture script and it works fine.
    Quick question though. I need to make a small change in xml file created without re-mapping a window. How can I manually get Dexterity GUI field names from GP?

    Appreciate your help, thanks.

    Austin

    [ Albert's reply.
    I emailed my answer a while ago.
    In addition to that I posted description with screenprints here. ]

  • Leave a Reply

    * Required
    ** Your Email is never shared