Jump to content

SAPGUI scripting works in AutoIt but not in luacom


Recommended Posts

Hi folks,

I need help with connecting to SAPGUI using Lua. I saw that you folks have scripts for connecting and automation of SAP gui.

I try to use Lua and its LuaCOM but it did not work for me.

Have anybody ever try it?

My script bellow always fail on this call application:Children(0) and LuaCOM crash.

I don't know what am I doing wrong.

Could anybody help me with this? I would be grateful.

-- 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]").restore
-- session.findById("wnd[0]").resizeWorkingPane 98,17,false
-- session.findById("wnd[0]/tbar[0]/okcd").text = "12"
-- session.findById("wnd[0]/tbar[0]/okcd").text = "3"

function help(t)
    for k,v in pairs(t) do print(k,v) end
end

require("luacom")

-- luacom.config.abort_on_API_error = true
-- luacom.config.abort_on_error = false

print("SapGuiAuto")
local Wrp = luacom.CreateObject ("SapROTWr.SapROTWrapper")
local SapGuiAuto = Wrp:GetROTEntry ("SAPGUI")
--local SapGuiAuto  = luacom.GetObject("SAPGUI")
if not SapGuiAuto then error("SapGuiAuto missing") else help(SapGuiAuto) end
print()

print("application")
local application = SapGuiAuto:GetScriptingEngine()
if not application then error("application failed") else help(application) end
print()

print("connection")
local connection = application:Children(0)
if not connection then error("connection failed") else help(connection) end
print()

print("session")
local session = connection:Children(0)
if not session then error("session failed") else help(session)end
print()

   -- WScript.ConnectObject session,     "on"
   -- WScript.ConnectObject application, "on"
   
-- session.findById("wnd[0]").maximize

print("working")
c:\UserParameterSetter>lua.exe SAPconnect.lua
SapGuiAuto
_USERDATA_REF_  userdata: 01F03828

application
_USERDATA_REF_  userdata: 01F03878

connection

wm

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

Why not use AutoIt as it works and LUA doesn't?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I'm not sure you will get a lot of help on this subject.

SAPGUI automation using Autoit is not very widely used. And I don't know how many users of this forum do it with LUA.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Good luck :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...