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()
    println myFolder.name

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

    def OutMail = OutApp.CreateItem(0)

    OutMail.to = "an email address!!"
    OutMail.CC = ""
    OutMail.BCC = ""
    OutMail.Subject = "This is the Subject line"
    OutMail.Body = "Hi there"
    OutMail.Send()
    OutMail = null
    OutApp = null
}

///////////////////// end ////////////////
void listMnP (def thing) {
  println " >> Methods of ${thing.class} >>"
  thing.metaClass.methods.each {  method ->
    println "$method.name -> $method.parameterTypes"
  }
  println " >> Properties >>"
  thing.metaClass.properties.each { prop ->
    print "$prop.name -> "
    try {println thing[prop.name]} 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
3
Online Archive - mbeed...@cryoserver.com
>> Methods of class org.codehaus.groovy.scriptom.ActiveXObject >>
Caught: com.jacob.com.ComFailException: Can't map name to dispid: metaClass
com.jacob.com.ComFailException: Can't map name to dispid: metaClass
        at com.jacob.com.Dispatch.invokev(Native Method)
        at com.jacob.com.Dispatch.invokev(Dispatch.java:858)
        at com.jacob.com.Dispatch.get(Dispatch.java:1258)
        at 
com.jacob.activeX.ActiveXComponent.getProperty(ActiveXComponent.java:171)
        at scanMailbox.listMnP(scanMailbox.groovy:61)
        at scanMailbox$_run_closure2.doCall(scanMailbox.groovy:45)
        at scanMailbox$_run_closure2.doCall(scanMailbox.groovy)
        at scanMailbox.run(scanMailbox.groovy:37)

Merlin Beedell

Reply via email to