RecordDefn Class Methods
In this section, the RecordDefn class methods are presented in alphabetical order.
Syntax
AddField(existing_fieldname)
Description
Use this method to create a new record field definition for a given field populated with default record field definition values. The new record field is appended to the list of record fields.
Parameters
Parameter |
Description |
---|---|
existing_fieldname |
Specifies an existing field in the record definition. |
Returns
If the field is already on the record, the record field definition for that record field is returned.
Returns a null value if the field definition does not exist in the database.
Example
Local RecordDefn &myNewRecord = CreateRecordDefn();
&myNewRecord.Name = "MYRECORD_VW";
&myNewRecord.Description = "My new record";
&myNewRecord.SQL = "SELECT DISTINCT(PROCESS_INSTANCE) FROM PS_MESSAGE_LOG WHERE MESSAGE_NBR = 1018";
Local RecordFieldDefn &recField = &myNewRecord.AddField("MYFIELD");
If All(&recField) Then
&recField.Key = True;
End-If;
Syntax
Build()
Description
This method validates and saves a record definition, drops the view if it exists, and then runs the DDL to create or recreate the view in the database.
Parameters
None.
Returns
A Boolean value representing the following statuses.
Numeric Value |
Constant Value |
Description |
---|---|---|
0 |
%MDA_Success |
The record definition is built successfully. |
1 |
%MDA_Failed |
The record definition is not built. |
4 |
%MDA_Unsupported |
|
12 |
*%MDA_InvalidDefn |
The SQL text is invalid. |
14 |
*%MDA_NoWriteAccess |
The user does not have write permissions for the record. |
Example
Local RecordDefn &myNewRecord = CreateRecordDefn();
&myNewRecord.Name = "MYRECORD_VW";
&myNewRecord.Description = "My new record";
&myNewRecord.SQL = "SELECT DISTINCT(PROCESS_INSTANCE) FROM PS_MESSAGE_LOG WHERE MESSAGE_NBR = 1018";
Local RecordFieldDefn &recField = &myNewRecord.AddField("MYNEWFIELD");
If All(&recField) Then
&recField.Key = True;
End-If;
&retVal = &myNewRecord.Save();
/* do error checking … */
&retVal = &myNewRecord.Build();
/* do error checking … */
Syntax
GetField({n | field_name})
Description
Use this method to obtain the record field definition of the specified field.
Parameters
Parameter |
Description |
---|---|
n | field_name |
Specifies the field to be retrieved. This method takes the type as Any. The PeopleCode program is terminated if the specified field number does not exist on the record. |
Returns
A record field definition object for the specified field.
Returns a null value if the specified field does not exist on the record.
Example
Local RecordFieldDefn &recField = &myNewRecord.GetField("MYNEWFIELD");
Syntax
RemoveField({n | field_name})
Description
Use this method to remove a field from a record.
Parameters
Parameter |
Description |
---|---|
n | field_name |
Specifies the field to be removed. This method takes the type as Any. |
Returns
An integer representing the following statuses.
Numeric Value |
Constant |
Description |
---|---|---|
0 |
%MDA_Success |
The field is removed successfully. |
1 |
%MDA_Failed |
The field is not removed. |
Example
&returnValue = &myNewRecord.RemoveField("MYNEWFIELD");
Syntax
Save()
Description
Use this method to validate and save a record definition to the database.
Parameters
None.
Returns
A Boolean value representing the following statuses.
Numeric Value |
Constant Value |
Description |
---|---|---|
0 |
%MDA_Success |
The record definition is saved successfully. |
1 |
%MDA_Failed |
The record definition is not saved. |
2 |
%MDA_UseAppDesigner |
The record was not created using the PeopleCode RecordDefn class. |
4 |
%MDA_Unsupported |
The record type is not a SQL view. |
5 |
%MDA_Duplicate |
The specified record definition already exists. |
12 |
%MDA_InvalidDefn |
This value is returned when the validation fails. The detailed validation error messages are available through the Messages property. |
14 |
%MDA_NoWriteAccess |
The user does not have write permissions to the record. |
15 |
%MDA_SQLNotSaved |
The record is saved, but the SQL is not saved. |
Example
Local RecordDefn &myRecord = GetRecordDefn("MYRECORD_VW");
If All(&myRecord) Then
&myRecord.Description = "My new record description";
&retVal = &myRecord.Save();
/* do error checking … */
&retVal = &myNewRecord.Build();
/* do error checking … */
End-If;
Syntax
SaveAsView(record_name)
Description
This method sets the RuntimeDefn flag, changes the record type to View, validates, and saves the record definition to the database.
Parameters
Parameter |
Description |
---|---|
record_name |
Specifies the new record, which is saved as a view. |
Returns
A Boolean value representing the following statuses.
Numeric Value |
Constant Value |
Description |
---|---|---|
0 |
%MDA_Success |
The record definition is successfully saved as a view. |
1 |
%MDA_Failed |
The record definition is not saved as a view. |
5 |
%MDA_Duplicate |
The specified record already exists. |
12 |
%MDA_InvalidDefn |
This value is returned when the validation fails. The detailed validation error messages are available through the Messages property. |
15 |
%MDA_SQLNotSaved |
The record is saved, but the SQL is not saved. |
Example
&retVal = &srcRecord.SaveAsView("RT_VIEW");
Syntax
Validate()
Description
Use this method to validate a record definition.
Parameters
None.
Returns
A Boolean value. True if the record definition is successfully validated; false otherwise. If it returns false, the detailed error messages are available through the Messages property.
Example
&retVal = &srcRecord.Validate();