In general we use Component Interfaces to perform the following actions
- Create a new Instance of data
- Get existing Instance of data
- Retrieve a list of instances of data
Creating new instance of data:
1. Get a session object
2. Get a Component Interface
3. Set the Create keys
2. Get a Component Interface
3. Set the Create keys
4. Use the Create() method to create an instance of the data
5. Use Save() method , So the instance of the data will be saved to the database.
5. Use Save() method , So the instance of the data will be saved to the database.
In order to create new set of data the code can be modified in the following way
1) Get a session object
A session has to declared with a data type (i.e. API Type) & Need to get current PeopleSoft Session.From the above coding, it is
Local ApiObject&oSession, &oSampleCi;
rem ***** Get current PeopleSoft Session *****;
&oSession = %Session;
|
2) Get a Component Interface
Use the GetCompIntfc method with a session object to get the Component Interface.
Make sure that you are inputting valid CI name or else you will receive an error
rem ***** Get the Component Interface *****;
&oSampleCi = &oSession.GetCompIntfc(CompIntfc.SAMPLE_CI);
If &oSampleCi = Null Then
errorHandler();
throw CreateException(0, 0, "GetCompIntfc failed");
End-If;
|
At this point you have the structure of the Component Interface it is not yet populated with any data
3) Set the Create Keys
These values will make a new instance of data that has to be populated into db
Make sure you are inputting unique key values
rem ***** Set Component Interface Get/Create Keys *****;
&oSampleCi.EMPLID = “2344”;
|
4) Use the Create() method to instantiate the data
Need to remove [rem] to the Create method
Add [rem] to Get () method as we are not getting any instances of the data from db
I.e. it looks like
rem ***** Execute Get *****;
rem If Not &oSampleCi.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 &oSampleCi.Create() Then;
rem ***** Unable to Create Component Interface for the Add keys provided. *****;
errorHandler();
throw CreateException(0, 0, "Create failed");
End-If;
|
This successfully creates the new instance of the data , It’s not yet saved into DB
5) Set the values for the rest of the fields and execute Save() Method to successfully save the new instance of the data into DB
Remove [rem] from all the individual fields and assign the value
Remove [rem] for the Save () method
rem ***** Begin: Get/Set Component Interface Properties *****;
rem ***** Get/Set Level 0 Field Properties *****;
&fileLog.WriteLine("&oSampleCi.EMPLID = " | "2234");
&oSampleCi.EMPLID = "2234";
&fileLog.WriteLine("&oSampleCi.MOBILE_PHONE = " | "9985");
&oSampleCi.MOBILE_PHONE = "9985";
&fileLog.WriteLine("&oSampleCi.NAME = " | "Varma,penumatsa");
&oSampleCi.NAME = "Varma,penumatsa";
&fileLog.WriteLine("&oSampleCi.SEX = " | "M");
&oSampleCi.SEX = "M";
rem ***** Set/Get SAMPLECI_1 Collection Field Properties -- Parent: PS_ROOT Collection *****;
&oSampleci1Collection = &oSampleCi.SAMPLECI_1;
Local integer &i17;
For &i17 = 1 To &oSampleci1Collection.Count;
&oSampleci1 = &oSampleci1Collection.Item(&i17);
&fileLog.WriteLine("&oSampleci1.DEPTID = " | "110");
&oSampleci1.DEPTID = "110";
&fileLog.WriteLine("&oSampleci1.DEPTNAME = " | "Finance");
&oSampleci1.DEPTNAME = "Finance";
End-For;
rem ***** End: Get/Set Component Interface Properties *****;
rem ***** Execute Save *****;
If Not &oSampleCi.Save() Then;
errorHandler();
throw CreateException(0, 0, "Save failed");
End-If;
|
After running this, automatically new set of data will be uploaded into db.
Get an existing Instance of data
In order to Get a new set of data the code can be modified in the following way
1) Get a session object
Session has to declared with a data type (i.e. API Type) & Need to get current PeopleSoft Session .From the above coding it is
Local ApiObject&oSession, &oSampleCi;
rem ***** Get current PeopleSoft Session *****;
&oSession = %Session; |
2) Get a Component Interface
Use the GetCompIntfc method with a session object to get the Component Interface.
Make sure that you are inputting valid CI name or else you will receive an error
rem ***** Get the Component Interface *****;
&oSampleCi = &oSession.GetCompIntfc(CompIntfc.SAMPLE_CI);
If &oSampleCi = Null Then
errorHandler();
throw CreateException(0, 0, "GetCompIntfc failed");
End-If;
|
At this point you have the structure of the Component Interface it is not yet populated with any data
3) Set the GET Keys
These values will make a new instance of data that has to be populated into db
Make sure you are inputting unique key values
rem ***** Set Component Interface Get/Create Keys *****;
&oSampleCi.EMPLID = "2234";
|
4) Use the GET() method to instantiate the data
I.e. it looks like
rem ***** Execute Get *****;
If Not &oSampleCi.Get() Then
rem ***** No rows exist for the specified keys.*****;
errorHandler();
throw CreateException(0, 0, "Get failed");
End-If;
rem ***** Execute Create ******;
rem If Not &oSampleCi.Create() Then;
rem ***** Unable to Create Component Interface for the Add keys provided. *****;
rem errorHandler();
rem throw CreateException(0, 0, "Create failed");
rem End-If; |
Remove [rem] from all the individual fields and assign the value
Remove [rem] for the Save () method
rem ***** Begin: Get/Set Component Interface Properties *****;
rem ***** Get/Set Level 0 Field Properties *****;
&fileLog.WriteLine("&oSampleCi.EMPLID = " | &oSampleCi.EMPLID);
&oSampleCi.EMPLID = &oSampleCi.EMPLID;
&fileLog.WriteLine("&oSampleCi.MOBILE_PHONE = "&oSampleCi.MOBILE_PHONE);
&oSampleCi.MOBILE_PHONE = &oSampleCi.MOBILE_PHONE;
&fileLog.WriteLine("&oSampleCi.NAME = " | &oSampleCi.NAME);
&oSampleCi.NAME = &oSampleCi.NAME;
&fileLog.WriteLine("&oSampleCi.SEX = " | &oSampleCi.SEX);
&oSampleCi.SEX = &oSampleCi.SEX;
rem ***** Set/Get SAMPLECI_1 Collection Field Properties -- Parent: PS_ROOT Collection *****;
&oSampleci1Collection = &oSampleCi.SAMPLECI_1;
Local integer &i17;
For &i17 = 1 To &oSampleci1Collection.Count;
&oSampleci1 = &oSampleci1Collection.Item(&i17);
&fileLog.WriteLine("&oSampleci1.DEPTID = " | &oSampleci1.DEPTID);
&oSampleci1.DEPTID = &oSampleci1.DEPTID;
&oSampleci1.DEPTNAME = &oSampleci1.DEPTNAME;
End-For;
rem ***** End: Get/Set Component Interface Properties *****;
rem ***** Execute Save *****;
If Not &oSampleCi.Save() Then;
errorHandler();
throw CreateException(0, 0, "Save failed");
End-If; |
No comments:
Post a Comment