Sending Outlook Meeting Request Using PeopleCode

Your rating: None Average: 3.8 (4 votes)

The code was provided by a guest by the name of Nate. I wanted to post the code as a blog entry to give it more visibility. The original forum question is http://compshack.com/forum/peoplesoft/peoplesoft-technical/sending-meeti...

I haven't used/tested the code, so please provide your feedback in the comments section below if you have.

import PT_MCF_MAIL:*;

/*Declare variables*/
Local Record &cache = CreateRecord(Record.Z_CAL_CACHE);
Local string &guid;
Local string &url;
Local string &dateStr = DateTimeToLocalizedString(AUC_PLAN_TASKS.END_DT, "MM/dd/yyyy");
Local string &dateStamp = DateTimeToLocalizedString(%Datetime, "MM/dd/yyyy hh:mm:ss");
Local number &sequence_nbr;
Local string &plan_id = AUC_PLAN_HDR.AUC_PLAN_ID;
Local string &task_id = AUC_PLAN_TASKS.AUC_TASK_ID;
Local string &task_owner = AUC_PLAN_TASKS.TASK_OWNER;
Local string &mail_to;
Local string &organizer;

/*When user clicks send reminder button, determine if previous reminder was sent based on sequence number associated with Plan ID and Task #
in custom table. If sequence number is zero, this is the first reminder, so generate at GUID using RAWTOHEX. If sequence number is greater than 0, select
GUID from table. The GUID will be used in the Outlook formatted meeting request so that the existing event is correctly updated/moved in the
recipient's calendar. In either case, a new row will be inserted in to the CACHE table to track the sent meeting request.*/

SQLExec("SELECT MAX(SEQNBR) FROM PS_Z_CAL_CACHE WHERE AUC_PLAN_ID = :1 AND AUC_TASK_ID = :2", &plan_id, &task_id, &sequence_nbr);

If &sequence_nbr = 0 Then
SQLExec("SELECT RAWTOHEX(SYS_GUID()) FROM PS_INSTALLATION", &guid);
&sequence_nbr = 1;
Else
SQLExec("SELECT GUID FROM PS_Z_CAL_CACHE WHERE AUC_PLAN_ID = :1 AND AUC_TASK_ID = :2", &plan_id, &task_id, &guid);
&sequence_nbr = &sequence_nbr + 1;
End-If;

SQLExec("SELECT EMAILID FROM PSOPRDEFN WHERE oprid = :1", &task_owner, &mail_to);
SQLExec("SELECT A.EMAILID FROM PSOPRDEFN A, PS_AUC_PLAN_HDR B WHERE B.PLAN_OWNER = A.OPRID AND B.AUC_PLAN_ID =:1", &plan_id, &organizer);

rem MessageBox(0, "", 30000, 1, "Task Owner: " | &task_owner | ", Mail To: " | &mail_to);

/*Prepare data and insert into CACHE table and capture values for for Outlook reminder*/
&cache.GUID.Value = &guid;
&cache.SEQNBR.Value = &sequence_nbr;
&cache.START_DTTM.Value = DateTimeValue(&dateStr | " 12:00 PM");
&cache.END_DTTM.Value = DateTimeValue(&dateStr | " 12:00 PM");
&cache.DESCR.Value = "Task " | AUC_PLAN_TASKS.AUC_TASK_ID | " Due";
&cache.DESCR254.Value = "Task " | AUC_PLAN_TASKS.AUC_TASK_ID | " For Plan ID " | AUC_PLAN_HDR.AUC_PLAN_ID | " Is Due";
&cache.CATEGORY_DESCR.Value = "Bid/Contract Task Due";
&cache.AUC_PLAN_ID.Value = &plan_id;
&cache.AUC_TASK_ID.Value = &task_id;
&cache.DATETIME_DISPATCH.Value = DateTimeValue(&dateStamp);
&cache.Insert();
CommitWork();

/*Prepare date formats required for .ics format*/
&tempTime = DateTimeToTimeZone(&cache.START_DTTM.Value, "Local", "UTC");
&dtstart = DateTimeToLocalizedString(&tempTime, "yyyyMMdd'T'HHmmss'Z'");
&tempTime = DateTimeToTimeZone(&cache.END_DTTM.Value, "Local", "UTC");
&dtend = DateTimeToLocalizedString(&tempTime, "yyyyMMdd'T'HHmmss'Z'");
&tempTime = DateTimeToTimeZone(&cache.DATETIME_DISPATCH.Value, "Local", "UTC");
&dtstamp = DateTimeToLocalizedString(&tempTime, "yyyyMMdd'T'HHmmss'Z'");

Local string &CRLF = Char(13);
Local string &icalstring = "BEGIN:VCALENDAR" | &CRLF;
&icalstring = &icalstring | "PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN" | &CRLF;
&icalstring = &icalstring | "VERSION:2.0" | &CRLF;
&icalstring = &icalstring | "METHOD:REQUEST" | &CRLF;
&icalstring = &icalstring | "BEGIN:VEVENT" | &CRLF;
&icalstring = &icalstring | "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" | &organizer | &CRLF;
&icalstring = &icalstring | "ORGANIZER:MAILTO:" | &organizer | &CRLF;
&icalstring = &icalstring | "DTSTART:" | &dtstart | &CRLF;
&icalstring = &icalstring | "DTEND:" | &dtend | &CRLF;
&icalstring = &icalstring | "LOCATION:Conference Room" | &CRLF;
&icalstring = &icalstring | "TRANSP:OPAQUE" | &CRLF;
&icalstring = &icalstring | "SEQUENCE:" | &sequence_nbr | &CRLF;
&icalstring = &icalstring | "UID:" | &guid | &CRLF;
&icalstring = &icalstring | "DTSTAMP:" | &dtstamp | &CRLF;
&icalstring = &icalstring | "CATEGORIES:Meeting" | &CRLF;
&icalstring = &icalstring | "DESCRIPTION:Reminder" | &CRLF;
&icalstring = &icalstring | "SUMMARY:" | &cache.DESCR.Value | &CRLF;
&icalstring = &icalstring | "PRIORITY:5" | &CRLF;
&icalstring = &icalstring | "BEGIN:VALARM" | &CRLF;
&icalstring = &icalstring | "TRIGGER:PT1440M" | &CRLF;
&icalstring = &icalstring | "ACTION:DISPLAY" | &CRLF;
&icalstring = &icalstring | "DESCRIPTION:Reminder" | &CRLF;
&icalstring = &icalstring | "END:VALARM" | &CRLF;
&icalstring = &icalstring | "END:VEVENT" | &CRLF;
&icalstring = &icalstring | "END:VCALENDAR";

/*Format multi-part email and send*/
Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();

&email.From = &organizer;
&email.Recipients = &mail_to;
&email.Subject = "Task Reminder " | &cache.DESCR254.Value;

&email.AddHeader("", "method=REQUEST");
&email.AddHeader("", "charset=UTF-8");
&email.AddHeader("", "component=VEVENT");
&email.ContentType = "multipart/alternative";

Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = "Part 1: Email Text";
&text.ContentType = "text/html";

Local PT_MCF_MAIL:MCFBodyPart &iCal = create PT_MCF_MAIL:MCFBodyPart();
&iCal.Text = &icalstring;

&iCal.AddHeader("content-class", "urn:content-classes:calendarmessage");
&iCal.AddHeader("content-ID", "calendar_message");
&iCal.ContentType = "text/calendar;method=REQUEST; charset=UTF-8";

Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.SubType = "alternative; differences=Content-type";
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&iCal);
&email.MultiPart = ∓

Local integer &resp = &email.Send();
Local boolean &done;

Evaluate &resp
When %ObEmail_Delivered
/* every thing ok */
&done = True;
Break;

When %ObEmail_NotDelivered
/*-- Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses */

&done = False;
Break;

When %ObEmail_PartiallyDelivered
/* Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses; */

&done = True;
Break;

When %ObEmail_FailedBeforeSending
/* Get the Message Set Number, message number;
Or just get the formatted messages from &email.ErrorDescription,
&email.ErrorDetails;*/


&done = False;
MessageBox(0, "", 30000, 1, "Failed Before Sending" | "Error Description: " | &email.ErrorDescription | "Error Detail: " | &email.ErrorDetails);
Break;
End-Evaluate;

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.

Post new comment

CAPTCHA
The question below is to prevent automated spam submissions.
2 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.