groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Merlin Beedell <>
Subject Getting Methods/Properties of objects under "Scriptom"
Date Thu, 16 Nov 2017 15:48:21 GMT
I am trying to analyse a large chunk of emails in Outlook.  I thought that I could re-write
my VBA script using Groovy with "scriptom" to access the COM objects - and indeed it works.
Yippee! So I can send an email and query the folder tree etc.
However, I am a curious person, and sometime would like to "query" the methods and properties
of an Object - and the "listMnP (Object)" [see below] works nicely for Java objects.
This often helps when I am trying to match the documentation that I can find on Google, to
the various objects that I am accessing.
However, I get a "Can't map name to dispid: metaClass" error - which is probably quite understandable.
 Is it possible to query the Methods and Properties of a dynamic object in any way?

org.codehaus.groovy.scriptom.Scriptom.inApartment {

    def OutApp = new org.codehaus.groovy.scriptom.ActiveXObject("Outlook.Application")
    def myNameSpace = OutApp.GetNameSpace("MAPI")
    println myNameSpace.Folders.Count
    def myFolder = myNameSpace.Folders.GetFirst()

listMnP myFolder   /// this should cause the object "myFolder" to list its Methods and Properties
- but it errors.

    def OutMail = OutApp.CreateItem(0) = "an email address!!"
    OutMail.CC = ""
    OutMail.BCC = ""
    OutMail.Subject = "This is the Subject line"
    OutMail.Body = "Hi there"
    OutMail = null
    OutApp = null

///////////////////// end ////////////////
void listMnP (def thing) {
  println " >> Methods of ${thing.class} >>"
  thing.metaClass.methods.each {  method ->
    println "$ -> $method.parameterTypes"
  println " >> Properties >>" { prop ->
    print "$ -> "
    try {println thing[]} catch (Exception e) {println "-NoValue-"}
  try {println "Class Loader: ${thing.class.classLoader}"} catch (e) {println "No Class Loader"}


================== When run the "List Methods and Properties" function is not effective ===============

PS C:\opt\groovy\OutlookScripts> groovy .\scanMailbox.groovy
Online Archive -
>> Methods of class org.codehaus.groovy.scriptom.ActiveXObject >>
Caught: Can't map name to dispid: metaClass Can't map name to dispid: metaClass
        at Method)
        at com.jacob.activeX.ActiveXComponent.getProperty(
        at scanMailbox.listMnP(scanMailbox.groovy:61)
        at scanMailbox$_run_closure2.doCall(scanMailbox.groovy:45)
        at scanMailbox$_run_closure2.doCall(scanMailbox.groovy)

Merlin Beedell

View raw message