Thursday, 17 November 2016

How to call user profile CI through Peoplecode on Field Change

/* ===>

This is a dynamically generated PeopleCode template to be used only as a helper

to the application developer.

You need to replace all references to '[*]' OR default values with  references to

PeopleCode variables and/or a Rec.Fields. */







Local ApiObject &oSession, &oIobmUserProfile;

Local ApiObject &oEmailAddressesCollection, &oEmailAddresses;

Local ApiObject &oIDTypesCollection, &oIDTypes;

Local ApiObject &oAttributesCollection, &oAttributes;

Local ApiObject &oRolesCollection, &oRoles;

Local ApiObject &oRouteControlsCollection, &oRouteControls;



Function errorHandler()
 
   Local ApiObject &oPSMessageCollection, &oPSMessage;
 
   Local number &i;
 
   Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType;
 
 
 
   &oPSMessageCollection = &oSession.PSMessages;
 
   For &i = 1 To &oPSMessageCollection.Count
    
      &oPSMessage = &oPSMessageCollection.Item(&i);
    
      &sErrMsgSetNum = &oPSMessage.MessageSetNumber;
    
      &sErrMsgNum = &oPSMessage.MessageNumber;
    
      &sErrMsgText = &oPSMessage.Text;
    
      &fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);
      rem  WinMessage(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);
   End-For;
 
   rem ***** Delete the Messages from the collection *****;
 
   &oPSMessageCollection.DeleteAll();
 
End-Function;



try
 
   rem ***** Set the Log File *****;
 
 
   rem ***** Get current PeopleSoft Session *****;
 
   &oSession = %Session;
 
 
 
   rem ***** Set the PeopleSoft Session Error Message Mode *****;
 
   rem ***** 0 - None *****;
 
   rem ***** 1 - PSMessage Collection only (default) *****;
 
   rem ***** 2 - Message Box only *****;
 
   rem ***** 3 - Both collection and message box *****;
 
   &oSession.PSMessagesMode = 3;
 
 
 
   rem ***** Get the Component Interface *****;
 
   &oIobmUserProfile = &oSession.GetCompIntfc(CompIntfc.IOBM_USER_PROFILE);
 
   If &oIobmUserProfile = Null Then
    
      errorHandler();
    
      throw CreateException(0, 0, "GetCompIntfc failed");
    
   End-If;
 
 
 
   rem ***** Set the Component Interface Mode *****;
 
   &oIobmUserProfile.InteractiveMode = False;
 
   &oIobmUserProfile.GetHistoryItems = True;
 
   &oIobmUserProfile.EditHistoryItems = False;
 
 
 
   rem ***** Set Component Interface Get/Create Keys *****;
   &userid = Substring(IOBM_USER_PROF.EMPLID.Value, 7, 11);
   &oIobmUserProfile.UserID = &userid;
 
 
 
 
   rem ***** Execute Get *****;
   rem WinMessage(&a);
   <*
   If Not &oIobmUserProfile.Get() Then
    
      rem ***** No rows exist for the specified keys.*****;
      WinMessage("abc");
      errorHandler();
    
      throw CreateException(0, 0, "Get failed");
    
   End-If;
   *>
 
 
   rem ***** Execute Create ******;
   rem &a = &oIobmUserProfile.Create();
   rem WinMessage(&a);
   rem for creating new profile;
   If Not &oIobmUserProfile.Create() Then;
    
      rem ***** Unable to Create Component Interface for the Add keys provided. *****;
    
      errorHandler();
    
      throw CreateException(0, 0, "Create failed");
    
    
   End-If;
 
 
 
 
 
   rem ***** Begin: Get/Set Component Interface Properties *****;
 
   rem ***** Get/Set Level 0 Field Properties *****;
 
   &oIobmUserProfile.UserID = &userid;
   SQLExec("select distinct get_empl_name(emplid) from PS_ACAD_PROG where emplid = :1", IOBM_USER_PROF.EMPLID.Value, &Name);
   &oIobmUserProfile.UserDescription = &Name;
 
   &oIobmUserProfile.PrimaryPermissionList = "HCPPALL";
 
   &oIobmUserProfile.RowSecurityPermissionList = "HCDPALL";
 
   &oIobmUserProfile.OPERPSWD = &userid;
 
   &oIobmUserProfile.Encrypted = "1";
 
   &oIobmUserProfile.SymbolicID = "SYSADM1";
 
   &oIobmUserProfile.LanguageCode = "ENG";
 
   rem &oIobmUserProfile.MultiLanguageEnabled = [*];
 
   &oIobmUserProfile.CurrencyCode = "PKR";
 
   rem &oIobmUserProfile.AccountLocked = [*];
 
   &oIobmUserProfile.ProcessProfilePermissionList = "HCSPPRFL";
 
   &oIobmUserProfile.NavigatorHomePermissionList = "HCSPNAVHP";
 
   rem &oIobmUserProfile.FailedLogins = [*];
 
   rem &oIobmUserProfile.ExpertEntry = [*];
 
   rem &oIobmUserProfile.Opertype = [*];
 
   rem &oIobmUserProfile.UserIDAlias = [*];
 
   rem &oIobmUserProfile.AllowSwitchUser = [*];
 
   &oIobmUserProfile.OPERPSWDCONF = &userid;
 
   rem &oIobmUserProfile.ReassignUserID = [*];
 
   rem &oIobmUserProfile.ReassignWork = [*];
 
   rem &oIobmUserProfile.MPDEFAULMP = [*];
 
   rem &oIobmUserProfile.WorklistUser = [*];
 
   rem &oIobmUserProfile.EmailUser = [*];
 
   rem &oIobmUserProfile.AlternateUserID = [*];
 
   rem &oIobmUserProfile.SupervisingUserID = [*];
 
   rem &oIobmUserProfile.EffectiveDateFrom = [*];
 
   rem &oIobmUserProfile.EffectiveDateTo = [*];
 
 
 
   rem ***** Set/Get EmailAddresses Collection Field Properties -- Parent: PS_ROOT Collection *****;
 
   &oEmailAddressesCollection = &oIobmUserProfile.EmailAddresses;
 
   Local integer &i131;
 
   For &i131 = 1 To &oEmailAddressesCollection.Count;
    
      &oEmailAddresses = &oEmailAddressesCollection.Item(&i131);
    
    
      &oEmailAddresses.EmailType = "BUS";
    
    
      &oEmailAddresses.EmailAddress = "std_" | &userid | "@iobm.edu.pk";
    
    
      &oEmailAddresses.PrimaryEmail = "Y";
    
   End-For;
 
 
 
   rem ***** Set/Get IDTypes Collection Field Properties -- Parent: PS_ROOT Collection *****;
 
   &oIDTypesCollection = &oIobmUserProfile.IDTypes;
 
   Local integer &i135;
 
   For &i135 = 1 To &oIDTypesCollection.Count;
    
      &oIDTypes = &oIDTypesCollection.Item(&i135);
    
    
      &oIDTypes.IDType = "EMP";
    
    
    
      rem ***** Set/Get Attributes Collection Field Properties -- Parent: IDTypes Collection *****;
    
      &oAttributesCollection = &oIDTypes.Attributes;
    
      Local integer &i237;
    
      For &i237 = 1 To &oAttributesCollection.Count;
       
         &oAttributes = &oAttributesCollection.Item(&i237);
       
       
         &oAttributes.Fieldname = "EMPLID";
       
       
         &oAttributes.Recname = "PERSONAL_DATA";
       
       
         &oAttributes.AttributeValue = IOBM_USER_PROF.EMPLID.Value;
       
       
         &oAttributes.AttributeName = "EmplID";
         rem  WinMessage(&oAttributesCollection.Count);
      End-For;
    
   End-For;
 
 
   rem ***** Set/Get Roles Collection Field Properties -- Parent: PS_ROOT Collection *****;
 
 
   &oRolesCollection = &oIobmUserProfile.Roles;
   &oRoles = &oRolesCollection.Item(1);
   &oRoles.RoleName = "CS - Student";
 
 
   &oRolesCollection = &oIobmUserProfile.Roles;
   &oRoles = &oRolesCollection.InsertItem(1);
   &oRoles.RoleName = "PeopleSoft Guest";
 
 
 
   rem ***** End: Get/Set Component Interface Properties *****;
 
 
   rem ***** Execute Save *****;
   rem &a = &oIobmUserProfile.Save();
 
   If Not &oIobmUserProfile.Save() Then;
    
      errorHandler();
    
      throw CreateException(0, 0, "Save failed");
   Else
      MessageBox(0, "", 0, 0, "" | "Profile Created");
   End-If;
 
 
 
   rem ***** Execute Cancel *****;
 
   rem If Not &oIobmUserProfile.Cancel() Then;
 
   rem     errorHandler();
 
   rem     throw CreateException(0, 0, "Cancel failed");
 
   rem End-If;
 
 
 
catch Exception &ex
 
   MessageBox(0, "", 0, 0, "" | &ex.ToString());
 
 
end-try;

No comments:

Post a Comment