Performing Pre-Processing for the Activity Guide Pagelet

For classic activity guides, you can define a pagelet pre-processing method that will be executed every time an activity pagelet is loaded or reloaded in the WorkCenter pagelet area. This method must be named PageletPreProcess. The application class containing this method is identified on the Pagelet Options page.

In the following example for the Unified Navigation pagelet, each time the pagelet is reloaded, the PageletPreProcess method creates a link for Manage Related Content for each remote system configured under unified navigation.

import PTAI_ACTION_ITEMS:ActionItem;
import PTAI_ACTION_ITEMS:List;
import PTAI_ACTION_ITEMS:AGInterface;
import PTAI_ACTION_ITEMS:Constants;

class UninavPageletPreprocessor implements PTAI_ACTION_ITEMS:AGInterface
   method PageletPreProcess(&oList As PTAI_ACTION_ITEMS:List);
end-class;
<*  
 method PageletPreprocess() - This method will be called everytime UniNav pagelet is rendered. This function creates a new action item in the UniNav pagelet 
for all the remote RC services. If an earlier created remote service is deleted then the corresponding action item also will be deleted.
*>
method PageletPreProcess
   /+ &oList as PTAI_ACTION_ITEMS:List +/
   /+ Extends/implements PTAI_ACTION_ITEMS:AGInterface.PageletPreProcess +/
   Local SQL &sqlGetRemoteSvc;
   Local string &svcId, &svcName, &svcDescr, &svcParamname;
   Local boolean &boolStatus;
   Local integer &seq, &i;
   Local array of string &arrChildItems;;
   Local PTAI_ACTION_ITEMS:ActionItem &oItem = CreateObject("PTAI_ACTION_ITEMS:ActionItem");
   Local PTAI_ACTION_ITEMS:ActionItem &oNewItem = CreateObject("PTAI_ACTION_ITEMS:ActionItem");
   Local PTAI_ACTION_ITEMS:Constants &PTAI_CONSTANTS = CreateObject("PTAI_ACTION_ITEMS:Constants");
   <* Every time the pagelet is opened child items under the node 'Related Content Setup' will be deleted and recreated. Nodes are deleted and added again
      everytime because, if some remote services are deleted then it will get reflected in the tree immediately and to prevent the addition of duplicate nodes *>
   try
      &oItem.open("PAPP_UNITM8_PAPP_UNINA1003");
      &arrChildItems = &oItem.getChildActions();
      If All(&arrChildItems) Then
         For &i = 1 To &arrChildItems.Len
            &oItem.open(&arrChildItems [&i]);
            If Not &oItem.ItemId = "PAPP_UNITM9_PAPP_UNINA1003" Then
               try
                  &boolStatus = &oItem.delete();
               catch Exception &e1
               end-try;
            End-If;
         End-For;
      End-If;
      SQLExec("Select MAX(PTAI_SEQ) from PS_PTAI_ITEM where PTAI_LIST_ID = :1", &oList.ListId, &seq);
      &sqlGetRemoteSvc = GetSQL(SQL.EPPAI_GET_REMOTE_SVC);
      While &sqlGetRemoteSvc.Fetch(&svcId, &svcName, &svcDescr)
         &oNewItem.new(&svcId, &svcName, &oList.ListId);
         &oNewItem.DescrLong = &svcDescr;
         &oNewItem.ServiceId = &svcId;
         &oNewItem.ParentId = "PAPP_UNITM8_PAPP_UNINA1003";
         &oNewItem.Status = "1";
         &oNewItem.CreatedDateTime = %Datetime;
         &oNewItem.CreatedByOprid = %UserId;
         &oNewItem.LastUpdatedDateTime = %Datetime;
         &oNewItem.LastUpdatedByOprid = %UserId;
         &oNewItem.Target = "T";
         &oNewItem.Type = "C";
         Local PTAI_COLLECTION:Collection &oAssignmentColl = create PTAI_COLLECTION:Collection();
         Local PTAI_ACTION_ITEMS:ActionItemAssignments &oAssignment = create PTAI_ACTION_ITEMS:ActionItemAssignments();
         &oAssignment.AssignType = &PTAI_CONSTANTS.MEMBER_TYPE_ROLE;
         &oAssignment.AssignValue = "Portal Administrator";
         &oAssignmentColl = &oNewItem.getAssignments();
         &oAssignmentColl.InsertItem(&oAssignment As PTAI_COLLECTION:Collectable);
         &oNewItem.saveAssignments(&oAssignmentColl);
         &seq = &seq + 10;
         &oNewItem.Sequence = &seq;
         &boolStatus = &oNewItem.save();
      End-While;
      &sqlGetRemoteSvc.Close();
   catch Exception &e
   end-try;
end-method;