WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: domvalle@comcast.net on January 30, 2020, 07:19:03 AM

Title: mapi mLogOn question
Post by: domvalle@comcast.net on January 30, 2020, 07:19:03 AM
We are looking to post an appointment to a shared calendar.
We found the article 'Writing Appointments to Outlook' which works except when the user has Outlook already open.
Then it posts the appointment to the users cal instead.
If we terminate Outlook and use mLogOn("Applications Profile") then it works.
Is there another way to reference a shared calendar without naming second profile?
In this case the default user profile does have permissions to this cal...
Title: Re: mapi mLogOn question
Post by: domvalle@comcast.net on January 30, 2020, 07:48:48 AM
Interesting...
I exported the cal to an .ics file and found this:
   X-WR-RELCALID:{0000013D-8BE3-54B6-434C-A8F50B0D2554}
   X-WR-CALNAME:Applications
Otherwise I have no idea...
Title: Re: mapi mLogOn question
Post by: td on January 30, 2020, 08:09:19 AM
There are multiple articles about MAPI in the Tech Database.  You could consider perusing there for ideas.  Here is a link to one such article:

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/MAPI+MAPILogonEx~vs.~MAPILogon.txt (https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/MAPI+MAPILogonEx~vs.~MAPILogon.txt)
Title: Re: mapi mLogOn question
Post by: domvalle@comcast.net on January 30, 2020, 09:37:08 AM
Yes... I also found this one: OLE and OUTLOOK read mail other than inbox
using this example I was able to navigate and display the shared cal but the createItem still posts to the default.

AddExtender("WWMAP44I.DLL")
mhdl=mLogOn("Applications") ;gets handle
mailid="";important to initialize
olAppointmentItem=1
olByReference=4
recuring=0
olFolder="Applications"
myFolder= "Calendar" 

myOlApp = ObjectCreate("Outlook.Application")
objNameSpace = myOlApp.GetNamespace("MAPI")
objFolder1 = objNameSpace.Folders(olFolder);
objFolder=objFolder1.Folders(myFolder);

objFolder.Display                                                        ;-->this displays the shared cal we want...
pause("Test", "test" )

myItem = myOlApp.CreateItem(olAppointmentItem) ;-->but this sill posts to the users default cal
                                                                                  ; tried replacing myOlApp with objFolder but it will error
myItem.Subject = "Test Client Subject"
myItem.Location = "TriVin License Expirations"
myItem.Body = "This clients License Expirations"
myItem.BusyStatus = 3 ;0 Free , 1 Tentative, 2 Busy, 3 Out of office
;myItem.RecurrencePattern = 0 ;0 Daily
year=ItemExtract(1,TimeYmdHms ( ),":")
month=ItemExtract(2,TimeYmdHms ( ),":")
date=ItemExtract(3,TimeYmdHms ( ),":")
hour=ItemExtract(4,TimeYmdHms ( ),":")
minute=ItemExtract(5,TimeYmdHms ( ),":")+15
If minute>=60
    minute=minute-60
    hour=hour+1
EndIf
If hour>=24
    hour=hour-24
    day=day+1
EndIf
myItem.Start = StrCat(date,"/",month,"/",year," ",hour,":",minute,":00")
myItem.Duration = 90
type = olByReference
If recuring==1 Then myItem.Display
Else myItem.Save

ObjectClose(myItem)
ObjectClose(myOlApp)

mLogOff(mhdl)
Message("","DONE, Appointment created...")

Exit
Title: Re: mapi mLogOn question
Post by: td on January 30, 2020, 01:50:32 PM
Perhaps review this VBA discussion.  If it proves useful, the code should translate to WinBatch in a straight forward manor:

https://stackoverflow.com/questions/37353404/how-to-add-an-appointment-to-a-shared-calendar-in-outlook (https://stackoverflow.com/questions/37353404/how-to-add-an-appointment-to-a-shared-calendar-in-outlook)
Title: Re: mapi mLogOn question
Post by: domvalle@comcast.net on January 31, 2020, 06:18:53 AM
THANKS! That example was helpful...
I replaced the
. . . myItem = myOlApp.CreateItem(olAppointmentItem)
with
. . . myItem = objFolder.Items.Add(olAppointmentItem)
and it worked!!!!