Getting an Existing Instance of Data Example
The following is an example of how to get an existing instance of a Component Interface.
In this example, you are getting an existing instance of data for the EMPL_CHKLST_BC Component Interface, which is based on the EMPLOYEE_CHECKLIST component. The following is the complete code sample: the steps explain each line.
Local ApiObject &MYSESSION;
Local ApiObject &MYCI;
&MYSESSION = %Session;
&MYCI = &MYSESSION.GetCompIntfc(COMPINTFC.EMPL_CHKLST_BC);
&MYCI.EMPLID= "8001";
&MYCI.Get();
/* Get checklist Code */
&CHECKLIST_CD = &MYCI.CHECKLIST_CD;
/* Set Effective date */
&MYCI.EFFDT = "05-01-1990";
.
.
.
If NOT(&MYCI.Save()) Then
/* save didn’t complete */
&COLL = &MYSESSION.PSMessages;
For &I = 1 to &COLL.Count
&ERROR = &COLL.Item(&I);
&TEXT = &ERROR.Text;
/* do error processing */
End-For;
&COLL.DeleteAll();
End-if;-
Get a session object.
Before you can get a Component Interface, you have to get a session object. The session controls access to the Component Interface, provides error tracing, enables you to set the runtime environment, and so on.
&MYSESSION = %Session; -
Get a Component Interface.
Use the GetCompIntfc method with a session object to get the Component Interface. You must specify a Component Interface definition that has already been created. You receive a runtime error if you specify a Component Interface that doesn’t exist.
&MYCI = &MYSESSION.GetCompIntfc(COMPINTFC.EMPL_CHKLST_BC);After you execute the GetCompIntfc method, you have only the structure of the Component Interface. You haven’t populated the Component Interface with data yet.
-
Set the GETKEYS.
These are the key values required to return a unique instance of existing data. If the keys you specify allow for more than one instance of the data to be returned, or if no instance of the data matching the key values is found, you receive a runtime error.
&MYCI.EMPLID = "8001"; -
Get the instance of data for the Component Interface.
After you set the key values, you have to use the Get method.
&MYCI.Get();This populates the Component Interface with data, based on the key values you set.
-
Get field values or set field values.
At this point, you can either get values or set values.
&CHECKLIST_CD = &MYCI.CHECKLIST_CD; /* OR */ &MYCI.EFFDT = "05-01-1990";If you have specified InteractiveMode as True, every time you assign a value, any PeopleCode programs associated with that field (either with record field or the component record field) fires (FieldEdit, FieldChange, and so on.)
-
Save or Cancel the Component Interface, as appropriate.
If you’ve changed values and you want to save your changes to the database, you must use the Save method.
If NOT(&MYCI.Save()) ThenThe Save method returns a Boolean value: True if the save was successful, False otherwise. Use this value to do error checking.
The standard PeopleSoft save business rules (that is, any PeopleCode programs associated with SaveEdit, SavePreChange, WorkFlow, and so on.) are executed. If you didn’t specify the Component Interface to run in interactive mode, FieldEdit, FieldChange, and so on, also run at this time.
Note:
If you’re running a Component Interface from an Application Engine program, the data won’t actually be committed to the database until the Application Engine program performs a COMMIT.
If you don’t want to save any changes to the data, use the Cancel method. The Component Interface is reset to the state it was in just after you used the GetCompIntfc method.
&MYCI.Cancel();This is similar to a user pressing ESC while in a component, and choosing to not save any of their changes.
-
Check Errors.
You can check if there were any errors using the PSMessages property on the session object.
If NOT(&MYCI.Save()) Then /* save didn’t complete */ &COLL = &MYSESSION.PSMessages; For &I = 1 to &COLL.Count &ERROR = &COLL.Item(&I); &TEXT = &ERROR.Text; /* do error processing */ End-For; &COLL.DeleteAll(); End-if;If there are multiple errors, all errors are logged to the PSMessages collection, not just the first occurrence of an error. As you correct each error, delete it from the PSMessages collection.
The Text property of the PSMessage returns the text of the error message. At the end of this text is a contextual string that contains the name of the field that generated the error. The contextual string has the following syntax:
{ComponentInterfaceName.[CollectionName(Row).[CollectionName(Row).[CollectionName⇒ (Row)]]].PropertyName}For example, if you specified the incorrect format for a date field of the Component Interface named ABS_HIST, the Text property would contain the following string:
Invalid Date {ABS_HIST.BEGIN_DT} (90), (1)The contextual string (by itself) is available using the Source property of the PSMessage.
Note:
If you’ve called your Component Interface from an Application Engine program, all errors are also logged in the Application Engine error log tables.