Using PeopleCode with Generic Templates
Generic templates other than SYSTEMDEFAULT are usually used only in PeopleCode calls. The following sample code shows how to use a generic template called MYTEMPLATE to send out a notification:
import PT_WF_NOTIFICATION:NotificationAddress;
import PT_WF_NOTIFICATION:Notification;
import PT_WF_NOTIFICATION:NotificationTemplate;
Local array of string &aryValues;
Local array of NotificationAddress &mynotifyto;
Local NotificationAddress &mynotifyaddress;
Local Notification &mynotification;
&mynotifyto = CreateArrayRept(&mynotifyaddress, 0);
&emailid = "targetperson@example.com";
&mynotifyaddress = create NotificationAddress("", "", "", &emailid, "Email");
&mynotifyto.Push(&mynotifyaddress);
&mynotifytemplate = create NotificationTemplate("","", "MYTEMPLATE", "G");
/* Populate an array to contain the values needed by the template */
&aryValues = CreateArrayRept("", 0);
&aryValues.Push("FIRST VALUE");
&aryValues.Push("SECOND VALUE");
&xmlVars = &mynotifytemplate.SetupGenericVars(&aryValues);
&mynotifytemplate.GetAndExpandTemplate(%Language, &xmlVars);
/* At this point, the &mynotifytemplate should have every value resolved */
&mynotification = create Notification("sourceperson@example.com", %Date + %PerfTime, %Language);Note:
To ensure a unique timestamp for each notification that is sent,you must pass a DateTime value that includes milliseconds to the dttmCreated parameter. Because the %Datetime system variable always returns 0 for the milliseconds value, use the combination of %Date+%PerfTime instead.
See PeopleCode Language Reference: %Date system variable, PeopleCode Language Reference: %PerfTime system variable.
&mynotification.NotifyTo = &mynotifyto;&mynotification.Subject = &mynotifytemplate.Subject;&mynotification.Message = &mynotifytemplate.Text;&mynotification.Send();Note:
You can also use this code for component templates by replacing the G with a C. Then, populate the component name and market when calling the template as shown in the following example code. The template variables are all assumed to be in the page buffers.
&mynotifytemplate = create NotificationTemplate(%Component, %Market,⇒
"MYCOMPONENTTEMPLATE", "C");&xmlVars = &mynotifytemplate.SetupCompVarsAndRcpts(GetLevel0());
&mynotifytemplate.GetAndExpandTemplate(%Language, &xmlVars);