Using SQLExec and Record Objects

By Chris Malek | Mon, Jul 11, 2011

Here is a quick code snippet to show how to use SQLExec to pull data into a record object not using the key fields of the record. It is not clear in PeopleBooks how to use Record objects with SQLExec. I use record objects all over the place in my peoplecode. Here is a quick way to do a select to populate a record object NOT using key fields.

In this example we will populate a record object for PSOPRDEFN for the user profile that has the employee id of “EE2343.” The only key field on PSORPDEFN is OPRID which we are trying to find.

Local Record &recO;
&recO = CreateRecord(Record.PSOPRDEFN);
SQLExec("%selectall(:1) WHERE PSOPRDEFN.EMPLID = :2", &recO, "EE2343", &recO);

The great thing about this is that it automatically pulls all the fields. If you later add or remove fields from the record you are selecting from you do not have to touch this code because “%selectall” will dynamically figure out the fields based on the record definition.

Article Categories