Initializing an Activity Guide Instance

Whether an activity guide is created dynamically or manually, each instance created from a template can be initialized through a PeopleCode method that you define specifically for this purpose. This method is identified on the Advanced Options page for the activity guide template.

Limit initialization to operations such as inactivating steps based on the context, initializing the step statuses, updating step assignments, and so on. Also, perform any updates, additions, or deletions that impact translations. Oracle recommends to avoid complex operations such as accessing or updating application tables.

Note:

To create your own application class to initialize an activity guide instance, you can clone the PTAI_UTILITIES:InstanceIDCreation class and then modify your copy to suit the needs of your specific activity guide.

In the following example, the PTAI_UTILITIES:InstanceIDCreation class implements and extends the delivered PTAI_ACTION_ITEMS:AGInterface class. The constructor method implements the delivered abstract method by copying the action item assignments from the template and adding the user ID of the current user who instantiates the activity guide.

import PTAI_ACTION_ITEMS:*;
import PTAI_ACTION_ITEMS:AGInterface;
import PTAI_COLLECTION:*;
import PTAI_ACTION_ITEMS:Member:*;
class InstanceIDCreation implements PTAI_ACTION_ITEMS:AGInterface
   method InstanceCreation(&list As PTAI_ACTION_ITEMS:List);
end-class;
/**
* Sets the Instance items status to Assigned and Assigned to Operator ID to %User id.
**/
method InstanceCreation
   /+ &list as PTAI_ACTION_ITEMS:List +/
   /+ Extends/implements PTAI_ACTION_ITEMS:AGInterface.InstanceCreation +/
   Local array of string &childItemIds;
   Local integer &i;
   Local boolean &return;
   Local string &ptai_mbr_name, &ptai_mbr_type, &ptai_privset_ID, &ListID, &templateID, &templatelabel, &templatelabel_lng;
   Local PTAI_ACTION_ITEMS:ActionItem &item;
   Local PTAI_COLLECTION:Collection &members, &buttons, &contextfields;
   Local PTAI_ACTION_ITEMS:Member &member;
   Local PTAI_ACTION_ITEMS:Privilege &privileges;
   Local PTAI_ACTION_ITEMS:PgltButtons &button;
   &list.Status = "IP";
   SQLExec("Select PTAI_PARENT_TMPL From PS_PTAI_LIST Where PTAI_LIST_ID = :1 ", &list.ListId, &templateID);
   rem get the template label;
   SQLExec("Select PTAI_LABEL From PS_PTAI_LIST Where PTAI_LIST_ID = :1 ", &templateID, &templatelabel);
   If %Language <> %Language_Base Then
      SQLExec("Select PTAI_LABEL From PS_PTAI_LIST_LNG Where PTAI_LIST_ID =:1 AND LANGUAGE_CD=:2", &templateID, %Language, &templatelabel_lng);
      If All(&templatelabel_lng) Then
         &templatelabel = &templatelabel_lng;
      End-If;
   End-If;
   &list.Label = &templatelabel;
   &return = &list.save();
   <*
   rem the button label and method;
   &buttons = create PTAI_COLLECTION:Collection();
   &button = create PTAI_ACTION_ITEMS:PgltButtons("Cancel", "CancelAG");
   &buttons.InsertItem(&button);
   &button = create PTAI_ACTION_ITEMS:PgltButtons("Continue Later", "ExitAG");
   &buttons.InsertItem(&button);
   rem &button = create PTAI_ACTION_ITEMS:PgltButtons("Mark Task Completed", "MarkComplete");
   rem &buttons.InsertItem(&button);
   &list.SavePgltBtn(&buttons);  
   *>
   Rem change the status of the action items;
   &childItemIds = &list.getActionItems();
   For &i = 1 To &childItemIds.Len
      &item = create PTAI_ACTION_ITEMS:ActionItem();
      &item.open(&childItemIds [&i]);
      &item.Status = "1";
      /*
         &item.PackageRoot = "W3EB_LIFE_EVENT";
         &item.QualifyPath = ":";
         &item.AppClassID = "ItemStatus";
	*/
      Local PTAI_COLLECTION:Collection &oAssignmentColl = create PTAI_COLLECTION:Collection();
      Local PTAI_ACTION_ITEMS:ActionItemAssignments &oAssignment = create PTAI_ACTION_ITEMS:ActionItemAssignments();
      &oAssignment.AssignType = "USER";
      &oAssignment.AssignValue = %OperatorId;
      /* if you want to copy the assignments from template's action items to instance action items, call the getAssignments method and add your new user/role
		 assignments in the returned collection and then call saveAssignments with the combined collection object as shown below. Or if you just want to copy
		 the template assigments to instance and not adding any new assignments, you don't need the following 3 lines of code */
      &oAssignmentColl = &item.getAssignments();
      &oAssignmentColl.InsertItem(&oAssignment As PTAI_COLLECTION:Collectable);
      &item.saveAssignments(&oAssignmentColl);
      &return = &item.save();
   End-For;
   Rem Save the logged in UserID for security and privileges;
   &members = create PTAI_COLLECTION:Collection();
   &members = &list.getMembers();
   &ptai_mbr_name = %UserId;
   &ptai_mbr_type = "USER";
   SQLExec("Select PTAI_PRIVSET_ID From PS_PTAI_PRIVSET Where DESCR = 'Contributor' and PTAI_FEATURE = 'AI' AND ACTIVE_FLAG = 'A' AND PTAI_SYSTEM_ITEM = 'Y' ", &ptai_privset_ID);
   &member = create PTAI_ACTION_ITEMS:Member(&ptai_mbr_name, &ptai_mbr_type);
   &member.PrivilegeSetID = &ptai_privset_ID;
   &members.InsertItem(&member);
   &list.saveMembers(&members);
end-method;

Related Topics