Sunday 8 September 2024

CI Peoplecode to update Student Name

 /* ===>

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 File &fileLog;

Local ApiObject &oSession, &oCiPersonalData;

Local ApiObject &oCollNameTypeVwCollection, &oCollNameTypeVw;

Local ApiObject &oCollNamesCollection, &oCollNames;


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;

      Error MsgGet(&oPSMessage.MessageSetNumber, &oPSMessage.MessageNumber, &sErrMsgText);

      rem &fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText);

   End-For;

   rem ***** Delete the Messages from the collection *****;

   &oPSMessageCollection.DeleteAll();

End-Function;




Function UpdatePersonalData(&EmplId As string, &NameType As string, &EffDate As date, &CountryFormat As string, &LastName As string, &FirstName As string, &MiddleName As string, &SecondLastName As string) Returns boolean

   Local number &WorkAround;

   Local integer &CollCount1, &NameCount;

   

   

   try

      /* Initialize session */

      &oSession = %Session;

      &oSession.PSMessagesMode = 1;

      

      /* Get the Component Interface */

      &oCiPersonalData = &oSession.GetCompIntfc(CompIntfc.CI_PERSONAL_DATA);

      If &oCiPersonalData = Null Then

         errorHandler();

         throw CreateException(0, 0, "GetCompIntfc failed");

      End-If;

      

      /* Set Component Interface Mode */

      &oCiPersonalData.InteractiveMode = True;

      &oCiPersonalData.GetHistoryItems = True;

      &oCiPersonalData.EditHistoryItems = True;

      

      /* Set Component Interface Get/Create Keys */

      &oCiPersonalData.KEYPROP_EMPLID = &EmplId;

      

      /* Execute Get */

      If Not &oCiPersonalData.Get() Then

         errorHandler();

         throw CreateException(0, 0, "Get failed");

      End-If;

      

      /* Set/Get COLL_NAME_TYPE_VW Collection Field Properties */

      &oCollNameTypeVwCollection = &oCiPersonalData.COLL_NAME_TYPE_VW;

      &oCollNameTypeVw = &oCollNameTypeVwCollection.insertitem(&oCollNameTypeVwCollection.count);

      &WorkAround = &oCollNameTypeVw.itemnum;

      &CollCount1 = &oCollNameTypeVwCollection.count;

      &oCollNameTypeVw = &oCollNameTypeVwCollection.Item(&CollCount1);

      &oCollNameTypeVw.KEYPROP_NAME_TYPE = &NameType;

      

      /* Set Names */

      &oCollNamesCollection = &oCollNameTypeVw.COLL_NAMES;

      &NameCount = 0;

      Local integer &i122;

      For &i122 = 1 To 1

         &NameCount = &NameCount + 1;

         If &NameCount > 1 Then

            &oCollNames = &oCollNamesCollection.insertitem(&oCollNamesCollection.count);

            &WorkAround = &oCollNames.itemnum;

         End-If;

         

         &CollCount1 = &oCollNamesCollection.count;

         &oCollNames = &oCollNamesCollection.Item(&CollCount1);

         &oCollNames.KEYPROP_NAME_TYPE = &NameType;

         &oCollNames.KEYPROP_EFFDT = &EffDate;

         &oCollNames.PROP_COUNTRY_NM_FORMAT = &CountryFormat;

         &oCollNames.PROP_NAME_PREFIX = "";

         &oCollNames.PROP_NAME_SUFFIX = "";

         &oCollNames.PROP_LAST_NAME = &LastName;

         &oCollNames.PROP_FIRST_NAME = &FirstName;

         &oCollNames.PROP_MIDDLE_NAME = &MiddleName;

         &oCollNames.PROP_SECOND_LAST_NAME = &SecondLastName;

      End-For;

      

      /* Execute Save */

      If Not &oCiPersonalData.Save() Then

         errorHandler();

         throw CreateException(0, 0, "Save failed");

      End-If;

      

      /* Execute Cancel */

      If Not &oCiPersonalData.Cancel() Then

         errorHandler();

         throw CreateException(0, 0, "Cancel failed");

      End-If;

      

      /* Return True if successful */

      Return True;

      

   catch Exception &ex1

      Error MsgGet(0, 0, "Caught exception: " | &ex1.ToString());

      /* Return False if an error occurs */

      Return False;

   end-try;

   

End-Function;


Local boolean &isSuccessful;


&SQL1 = CreateSQL("select distinct emplid ,initcap(last_name) , initcap(first_name) ,initcap(middle_name) ,initcap(second_last_name) from ps_uod_name_load WHERE descr = 'rr' and ROWNUM <= 400");


While &SQL1.Fetch(&emplid, &LastName, &FirstName, &MiddleName, &SecondLastName)

   

   &isSuccessful = UpdatePersonalData(&emplid, "PRI", %Date, "001", &LastName, &FirstName, &MiddleName, &SecondLastName);

   

   If &isSuccessful Then

      

      SQLExec("update ps_uod_name_load set descr='true' where emplid =:1", &emplid);

      rem   MessageBox(0, "", 0, 0, "Update was successful.");

      

   Else

      rem MessageBox(0, "", 0, 0, "Update failed.");

      SQLExec("update ps_uod_name_load set descr='false' where emplid =:1 ", &emplid);

   End-If;

   

End-While;


No comments:

Post a Comment