Total Pageviews

Thursday, December 16, 2010

Code for Component Interface Mapping for level2

Changes Made for Dynamically generated Code By CI. If Any simplifications are there in code please send a Post.
Note:please drag the  code into Source Component last level record save pre change event.

Local File &fileLog;
Local ApiObject &oSession, &oNdes4Ci;
Local ApiObject &oNstdTbl5Collection, &oNstdTbl5;
Local ApiObject &oNstdTbl6Collection, &oNstdTbl6;

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);
   End-For;
   rem ***** Delete the Messages from the collection *****;
   &oPSMessageCollection.DeleteAll();
End-Function;

try
   rem ***** Set the Log File *****;
   &fileLog = GetFile("C:\temp\NDES4_CI.log", "w", "a", %FilePath_Absolute);
   &fileLog.WriteLine("Begin");
   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 = 1;

   rem ***** Get the Component Interface *****;
   &oNdes4Ci = &oSession.GetCompIntfc(CompIntfc.NDES4_CI);
   If &oNdes4Ci = Null Then
      errorHandler();
      throw CreateException(0, 0, "GetCompIntfc failed");
   End-If;

   rem ***** Set the Component Interface Mode *****;
   &oNdes4Ci.InteractiveMode = False;
   &oNdes4Ci.GetHistoryItems = True;
   &oNdes4Ci.EditHistoryItems = False;

   rem ***** Set Component Interface Get/Create Keys *****;
   &oNdes4Ci.NSTDID = NSTD_TBL1.NSTDID.Value;

   rem ***** Execute Get *****;
   REM If Not &oNdes4Ci.Get() Then
rem ***** No rows exist for the specified keys.*****;
   REM errorHandler();
   REM throw CreateException(0, 0, "Get failed");
   REM End-If;

   rem ***** Execute Create ******;
   If Not &oNdes4Ci.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 *****;
   &oNdes4Ci.NSTDID = NSTD_TBL1.NSTDID.Value;
   &fileLog.WriteLine("&oNdes4Ci.NSTDID = " | &oNdes4Ci.NSTDID);


   &oNdes4Ci.NSTDNAME = NSTD_TBL1.NSTDNAME.Value;
   &fileLog.WriteLine("&oNdes4Ci.NSTDNAME = " | &oNdes4Ci.NSTDNAME);

   &oNdes4Ci.NSTDGROUP = NSTD_TBL1.NSTDGROUP.Value;
   &fileLog.WriteLine("&oNdes4Ci.NSTDGROUP = " | &oNdes4Ci.NSTDGROUP);

   rem ***** Set/Get NSTD_TBL5 Collection Field Properties -- Parent: PS_ROOT Collection *****;
   &oNstdTbl5Collection = &oNdes4Ci.NSTD_TBL5;
   Local integer &i16;
   For &i16 = 1 To &oNstdTbl5Collection.Count;
      &oNstdTbl5 = &oNstdTbl5Collection.Item(&i16);
      &oNstdTbl5.NINSTID = NSTD_TBL2.NINSTID.Value;
      &fileLog.WriteLine("&oNstdTbl5.NINSTID = " | &oNstdTbl5.NINSTID);
    
      &oNstdTbl5.NINSTNAME = NSTD_TBL2.NINSTNAME.Value;
      &fileLog.WriteLine("&oNstdTbl5.NINSTNAME = " | &oNstdTbl5.NINSTNAME);
    
      &oNstdTbl5.LOC = NSTD_TBL2.LOC.Value;
      &fileLog.WriteLine("&oNstdTbl5.LOC = " | &oNstdTbl5.LOC);
    
    
      rem ***** Set NSTD_TBL6 Collection Field Properties -- Parent: NSTD_TBL5 Collection *****;
      rem &oNstdTbl6Collection = &oNstdTbl5.NSTD_TBL6;
      Local integer &i210;
      For &i210 = 1 To &oNstdTbl6Collection.Count;
         &oNstdTbl6 = &oNstdTbl6Collection.Item(&i210);
         &oNstdTbl6.N_M1 = NSTD_TBL3.N_M1.Value;
         &fileLog.WriteLine("&oNstdTbl6.N_M1 = " | &oNstdTbl6.N_M1);
      
         &oNstdTbl6.N_M2 = NSTD_TBL3.N_M2.Value;
         &fileLog.WriteLine("&oNstdTbl6.N_M2 = " | &oNstdTbl6.N_M2);
      
         &oNstdTbl6.N_TOTAL = NSTD_TBL3.N_TOTAL.Value;
         &fileLog.WriteLine("&oNstdTbl6.N_TOTAL = " | &oNstdTbl6.N_TOTAL);
      
         &oNstdTbl6.GRADE = NSTD_TBL3.GRADE.Value;
         &fileLog.WriteLine("&oNstdTbl6.GRADE = " | &oNstdTbl6.GRADE);
      
      End-For;
   End-For;
   rem ***** End: Get/Set Component Interface Properties *****;

   rem ***** Execute Save *****;
   If Not &oNdes4Ci.Save() Then;
      errorHandler();
      throw CreateException(0, 0, "Save failed");
   End-If;

   rem ***** Execute Cancel *****;
   If Not &oNdes4Ci.Cancel() Then;
      errorHandler();
      throw CreateException(0, 0, "Cancel failed");
   End-If;

catch Exception &ex
   rem Handle the exception;
   &fileLog.WriteLine(&ex.ToString());
end-try;
&fileLog.WriteLine("End");
&fileLog.Close();

No comments:

Post a Comment