Exporting from Outlook into Progress program

TomScott

New Member
I am reasonably new to programming so please try to ignore any obvious questions I might ask.

I am trying to create a link back and forth between a CRM program I have and outlook.

I currently can go to outlook but not the other way around.

Here's that Code.

DEF VAR hout as com-handle.
DEF VAR hitem as com-handle.

CASE p-state:

WHEN "items" THEN DO:
IF AVAIL prospers THEN DO:
FIND prospect WHERE
prospect.cid = gkcid AND
prospect.div = gkdiv AND
prospect.prospect = prospers.prospect NO-LOCK NO-ERROR.
IF AVAIL prospect THEN DO:
create "outlook.application" hout.
hitem = hout:createitem(2). /* olContactItem = 2 */
hitem:FullName = prospers.NAME.
hitem:JobTitle = prospers.perstitle.
hitem:Companyname = prospers.prospect.
hitem:Email1Address = prospers.email.
hitem:BusinessTelephoneNumber = prospers.telephone1.
hitem:Business2TelephoneNumber = prospers.ext.
hitem:BusinessAddress = prospers.Address1.
hitem:BusinessAddressCity = prospers.city.
hitem:BusinessAddressState = prospers.State.
hitem:BusinessAddressPostalCode= prospers.postalcd.
hitem:BusinessAddressCountry = prospers.country.
hitem:BusinessAddressCity = prospers.city.
hitem:Nickname = prospers.nickname.
hitem:Body= prospers.notes.
NO-RETURN-VALUE hitem:close(0). /* Close & Save = 0 */
RELEASE OBJECT hitem.
RELEASE OBJECT hout.
END.
END.
END.
END CASE.

However I don't know how to pull things out? Please forgive the incomplete nature of the following code:

def var hout as com-handle.
def var hitem as com-handle.
FIND prospect WHERE
Prospect.cid = "Test" AND
prospect.div = "TEST" AND
prospect.prospect = "Testprospect" NO-LOCK NO-ERROR.
create "outlook.application" hout.
hitem = hout:createitem(2). /* olContactItem = 2 */
IF hitem:FullName = "Bob Smith" THEN DO:
prospect.telephone1 = Hitem:BusinessTelephoneNumber.
NO-RETURN-VALUE hitem:close(0). /* Close & Save = 0 */
RELEASE OBJECT hitem.
RELEASE OBJECT hout.

And this runs, however nothing is in prospect.telephone1.

Then I found this code on progress talk:

DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hNameSpace AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hFolder AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hItem AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE X AS INTEGER NO-UNDO.

CREATE "Outlook.Application" hOutlook.

hNameSpace = hOutlook:GetNameSpace("MAPI").
hFolder = hNameSpace:AddressLists:ITEM(1).

DO X = 1 TO hFolder:AddressEntries:COUNT.
hItem = hFolder:AddressEntries:ITEM(X).
MESSAGE hItem:name.
END.

RELEASE OBJECT hItem.
RELEASE OBJECT hFolder.
RELEASE OBJECT hNameSpace.
RELEASE OBJECT hOutlook.

And the hITem:name is all that will work, and I didn't even think that was standard field. And it doesn't pull out name, only email. I tried changing this to fullname, thinking I was on the right track, but I'm stuck and I'm not really too sure what to try.

I apologize again if this all very obvious, and I thank you in the future should someone sees the error of my ways and can quickly help me.

Have a great day.

Tom
 

TomScott

New Member
I realize the FIND prospect code at the top is unnessary, I was trying something and forgot to take it out.
 

TomScott

New Member
I have at least gotten this to affect my prospect.email . It will now load "name" I don't know where it gets the information and I can only have Bob Smith in my contact list but it's doing something. Any ideas about how to differentiate between contacts and how to use outlook standard fields ex. Fullname, companyname,email?

I only used prospect.email due to its field length, this is what ended up in it. " Bob Smith (bsmith@test.com) " without the quotes



DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hNameSpace AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hFolder AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hItem AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE X AS INTEGER NO-UNDO.

CREATE "Outlook.Application" hOutlook.

hNameSpace = hOutlook:GetNameSpace("MAPI").
hFolder = hNameSpace:AddressLists:ITEM(1).

DO X = 1 TO hFolder:AddressEntries:COUNT.
hItem = hFolder:AddressEntries:ITEM(X).
MESSAGE hItem:NAME.
END.
FIND prospect WHERE
Prospect.cid = "Test" AND
prospect.div = "Test" AND
prospect.prospect = "Testprospect".
DISPLAY hitem:NAME.
DO:
prospect.email= Hitem:NAME.
END.
DISPLAY prospect.email.

RELEASE OBJECT hItem.
RELEASE OBJECT hFolder.
RELEASE OBJECT hNameSpace.
RELEASE OBJECT hOutlook.
 

TomScott

New Member
I have now gotten it to atleast affect my prospect.email, however it only puts "hitem:name" in there, I can't use standardized fields like fullname,email,companyname. And then the name isn't only the name, and it only pulls the first contact. So I get " Bob Smith (bsmith@test) " without the quotes. Any ideas about how to differentiate between contacts or how to use standard field names would be greatly appreciated.

Thanks and have a good one.

DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hNameSpace AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hFolder AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hItem AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE X AS INTEGER NO-UNDO.

CREATE "Outlook.Application" hOutlook.

hNameSpace = hOutlook:GetNameSpace("MAPI").
hFolder = hNameSpace:AddressLists:ITEM(1).

DO X = 1 TO hFolder:AddressEntries:COUNT.
hItem = hFolder:AddressEntries:ITEM(X).
MESSAGE hItem:NAME.
END.
FIND prospect WHERE
Prospect.cid = "test" AND
prospect.div = "test" AND
prospect.prospect = "Testprospect".
DISPLAY hitem:NAME.
DO:
prospect.email = Hitem:NAME.
END.
DISPLAY prospect.email.

RELEASE OBJECT hItem.
RELEASE OBJECT hFolder.
RELEASE OBJECT hNameSpace.
RELEASE OBJECT hOutlook.
 

Osborne

Active Member
Does changing hItem = hFolder:AddressEntries:ITEM(X) to hItem = hFolder:AddressEntries:GetContact(X) work?
 

TomScott

New Member
No, but thank you for the suggestion, I get the error, GetContact. Unknown name, then invalid component handle, and incompatible data types.
 

Osborne

Active Member
My mistake, GetContact is used with AddressEntry not AddressEntries:

http://msdn.microsoft.com/en-us/lib....interop.outlook.addressentry.getcontact.aspx.
http://pabweb.ru/32ch11n.shtml

It has been a while since I did this type of work, but if I remember correctly and as you have mentioned, the Item derived from AddressEntries differs from a contactitem - the following is available when a contact item but not when a standard item:

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.contactitem_members.aspx

I found the information was available when using GetContact - Outlook 2007 or later - but do not know how to obtain if not using GetContact. If you can use GetContact, does adding the extra lines in red work?:
Code:
[COLOR=#ff0000]DEFINE VARIABLE hContact AS COM-HANDLE NO-UNDO.

[/COLOR]hItem = hFolder:AddressEntries:ITEM(X).
[COLOR=#ff0000]hContact = hItem:GetContact.
DISPLAY hContact:FullName hContact:Email1Address.

IF VALID-HANDLE(hContact) THEN
   RELEASE OBJECT hContact.
[/COLOR]
 

jamesmc

Member
Heres something I wrote in 2008. Maybe you can use it?

Code:
DEFINE VARIABLE lvApplication   AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE lvNameSpace     AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE lvAddressList   AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE lvCounter       AS INTEGER    NO-UNDO.
DEFINE VARIABLE lvEntry         AS INTEGER    NO-UNDO.

MAINBLOCK:
DO:
    /* Create the application object */
    CREATE "Outlook.Application" lvApplication NO-ERROR.

    IF NOT VALID-HANDLE(lvApplication) THEN
    DO:
        MESSAGE "Could not create outlook application." VIEW-AS ALERT-BOX ERROR.
        LEAVE MAINBLOCK.
    END.

    ASSIGN lvNameSpace = lvApplication:GetNameSpace("MAPI").

    IF NOT VALID-HANDLE(lvNameSpace) THEN
    DO:
        MESSAGE "Could not get required namespace." VIEW-AS ALERT-BOX ERROR.
        LEAVE MAINBLOCK.
    END.

    /* Parameters are: Profile, Password, Show dialog, New session */
    lvNameSpace:Logon("Outlook", "", FALSE, TRUE).

    /* A handle to the item list in the Global Address List */
    lvAddressList = lvNameSpace:AddressLists:ITEM("Global Address List"):AddressEntries.

    /* Cycle through the items in the collection    */
    /* and see if any of them are individual users. */
    CONTACTLOOP:
    DO lvCounter = 1 TO lvAddressList:COUNT WITH FRAME b:
        
        /* Is the item an individual user item? */
        IF INT(lvAddressList:ITEM(lvCounter):DisplayType) <> 0 THEN
            NEXT CONTACTLOOP.

        DISPLAY lvAddressList:ITEM(lvCounter):NAME FORMAT "x(30)".

    END. /* CONTACTLOOP */

END. /* MAINBLOCK */

RELEASE OBJECT lvAddressList NO-ERROR.
RELEASE OBJECT lvNameSpace NO-ERROR.

lvApplication:QUIT().

RELEASE OBJECT lvApplication NO-ERROR.
 
Top