Jump to content
Server Maintenance This Week. ×

Grab Outlook Contacts with ScriptMaster


This topic is 6009 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Requirements:

ScriptMaster for FMP (AWESOME!)

Install Groovy and Reboot (yes you have to reboot, the ActiveXProxy won't work without it)

(During setup ActiveXProxy is an option, make sure it installs with Groovy.)

Recommended:

Install Advanced Security for Outlook

Should be in a startup script: (if this runs more than once, it stops working!)


SMLoadJar ( "file://C:/Program Files/Groovy/lib/scriptom-1.2.jar" ) & 

SMLoadJar ( "file://C:/Program Files/Groovy/lib/jacob.jar" )





Returns the Number of Contacts, followed by the Type and Name of each Item:



EvaluateGroovy ( "

		import org.codehaus.groovy.scriptom.ActiveXProxy;

	

	// Create the Outlook Object

	def oOutlook = new ActiveXProxy("Outlook.Application");

	

	//Logon to MAPI

	def oMAPI = oOutlook.GetNamespace("MAPI");

	oMAPI.Logon "Outlook";

	

	//Create the Contact Items Object

	def oContacts = oMAPI.GetDefaultFolder(10).Items;

	

	//Get the Number of Contact Items

	NumContacts = oContacts.Count.value;



	res = NumContacts + " Contacts Found";



	//Loop through the Contact Items

	for (i in 1..NumContacts) {

		//Create the Contact Object

		def oContact = oContacts.Item(i);

		

		//Get the MessageClass of the Item

		def msgclass = oContact.MessageClass.value;

		

		if (msgclass == "IPM.Contact") {		//If it is a Contact, do this

			res = res + "n" + msgclass + "tt" + oContact.FullName.value;

		} else if (msgclass == "IPM.DistList") {	//If if is a Distribution List, do this

			res = res + "n" + msgclass + "t>>>t" + oContact.DLName.value;

		} else {					//Otherwise, do this

			res = res + "n" + msgclass + "ttCANNOT HANDLE THIS CLASS";

		}

	}

	

	//Return the results we've gathered

	return res;

" )

Notice:

When working with COM objects in Groovy you often have to use '.value' to get the value of a property. If you don't, the Object Handle can be passed rather that the data you are expecting.

Link to comment
Share on other sites

This topic is 6009 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.