Hi,
Cannot get it to work with eventObj.........
This is my code, maybee you can make some sence out of it.
function GetName::OnClick(eventObj)
{
try
{
var cdoAddrEntry; // AddressEntry
var strData; // string
// JavaScript does not recognize constants!
// Define them explicitly or use their value.
var CdoPR_ACCOUNT = 0x3A00001F;
var CdoPR_DISPLAY_NAME = 0x3001001E;
var CdoPR_EMAIL = 0x39FE001E;
var CdoPR_DEPARTMENT_NAME = 0x3A18001F;
var CdoPR_OFFICE_LOCATION = 0x3A19001F;
var CdoPR_BUSINESS_TELEPHONE_NUMBER = 0x3A08001F;
//Start the CDO code to find a match.
cdoSession = new ActiveXObject("Mapi.session")
cdoSession.Logon(null,null,false,false,0); //Use the existing Outlook session.
// Get the AddressEntry of the recipient/current user.
cdoAddrEntry = cdoSession.CurrentUser;
AddPerson("//my:field1", "//my:field2", "//my:field3", false);
}
catch(e)
{
if (e.description.lastIndexOf('MAPI_E_LOGON_FAILED(80040111)') != -1)
XDocument.UI.Alert("You need to have Outlook started " +e.description);
else
XDocument.UI.Alert(e.description);
}
}
function AddPerson(nameFieldPath, mailFieldPath, accountFieldPath, allowManySelection)
{
try {
var oRecipients = null;
var oTestMessage=cdoSession.Outbox.Messages.Add();
oRecipients=cdoSession.AddressBook(oTestMessage.Recipients, "Select User", !allowManySelection, true, 1, "Add");
oRecipients.Resolve();
if(allowManySelection)
{
for(i=1;i<=oRecipients.Count;i++)
{
fillTextBox(nameFieldPath, oRecipients.item(i).AddressEntry.Fields(0x3001001E)+";");
fillTextBox(mailFieldPath, oRecipients.item(i).AddressEntry.Fields(0x39FE001E)+";");
fillTextBox(accountFieldPath, oRecipients.item(i).AddressEntry.Fields(0x3A00001F)+";");
}
}
else
{
fillTextBox(nameFieldPath, oRecipients.item(1).AddressEntry.Fields(0x3001001E));
fillTextBox(mailFieldPath, oRecipients.item(1).AddressEntry.Fields(0x39FE001E));
fillTextBox(accountFieldPath, oRecipients.item(1).AddressEntry.Fields(0x3A00001F));
}
}
catch(ex)
{
if(ex.description.lastIndexOf('MAPI_E_USER_CANCEL(80040113)') == -1)
{
if(ex.description.lastIndexOf('MAPI_E_NOT_INITIALIZED(80040605)') != -1)
XDocument.UI.Alert("No Address book connection, please close and reopen the form and select a valid Outlook profile");
else
XDocument.UI.Alert("Error retrieving user mail. Make sure Outlook is online: "+ex.description);
}
}
}
function fillTextBox(textBoxPath, value)
{
if(textBoxPath != "")
{
var textBox = XDocument.DOM.selectSingleNode(textBoxPath);
textBox.text += value;
XDocument.UI.Alert(value);
}
}
Many thanks in advance,
Hans