FieldDefn Class Methods

In this section, the FieldDefn class methods are presented in alphabetical order.

Syntax

Save()

Description

Use the Save method to validate and save a field definition to the database.

Parameters

None.

Returns

An integer representing the following statuses.

Numeric Value

Constant Value

Descriptoin

0

%MDA_Success

The field definition is saved successfully.

1

%MDA_Failed

The field definition is not saved.

2

%MDA_UseAppDesigner

The specified field is not created using the PeopleCode FieldDefn class.

4

%MDA_Unsupported

The specified field type is not supported in PeopleCode.

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 doesn’t have write permissions to the field.

Example

Local FieldDefn &newField = CreateFieldDefn();
If All(&newField) Then
   &newField.Name = "MYNEWFIELD";
   &newField.Type = %FieldType_Char;
   &newField.Description = "My new field";
   &retVal = &newField.SetLabel("MYNEWFIELD", "My field", "My New Field", True);
   /* do error checking … */
   Local date &myDate = Date3(1900, 1, 1);
   &retVal = &newField.SetTranslateValue("A", True, &myDate, "My New XLAT", "My XLAT");
   /* do error checking … */
   &retVal = &newField.Save();
   /* do error checking … */
End-If;

Syntax

SaveAs(New_FieldName)

Description

Use this method to set the RuntimeDefn flag, validate, and save the field definition to the database.

Labels are copied from the source field to the target field. The translate values are copied if the field type is character (CHAR) and the field length is less than or equal to 4.

Parameters

Parameter

Description

New_FieldName

Specifies the new name of the field.

Returns

An integer representing the following statuses.

Numeric Value

Constant Value

Description

0

%MDA_Success

The field definition is saved successfully.

1

%MDA_Failed

The field definition is not saved.

4

%MDA_Unsupported

The field type is not supported in PeopleCode.

5

%MDA_Duplicate

The given field 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 field.

Example

Local FieldDefn &mktField = GetFieldDefn("MARKET");
If All(&mktField) Then
   &mktField.Description = "My new Market field";
   &retVal = &mktField.SetLabel("MYMARKET", "My Market", "My New Market", True);
   /* do error checking … */
   Local date &myDate = Date3(1900, 1, 1);
   &retVal = &mktField.SetTranslateValue("A", True, &myDate, "My New Market", "My Market");
   /* do error checking … */
   &retVal = &mktField.SaveAs("MYMARKET");
   /* do error checking … */
End-If;

Syntax

SetLabel(Label_ID,Long_name,Short_name,Default_label)

Description

Use this method to add a new label or modify an existing label. At least one label is required for the field definition to be saved. Also, one label is required to be set as the default label for the field definition to be saved.

Parameters

Parameter

Description

Label_ID

Specifies the label as string.

Long_name

Specifies the long name of the field as string.

Short_name

Specifies the short name of the field as string.

Default_label

Specify a Boolean value whether the label entered in the Label_ID parameter is the default label or not.

Returns

An integer representing the following statuses.

Numeric Value

Constant Value

Description

0

%MDA_Success

The label for the field is updated successfully.

1

%MDA_Failed

The label for the field is not updated.

Example

Local FieldDefn &newField = CreateFieldDefn();
If All(&newField) Then
   &newField.Name = "MYNEWFIELD";
   &newField.Type = %FieldType_Char;
   &newField.Description = "My new field";
   &retVal = &newField.SetLabel("MYNEWFIELD", "My field", "My New Field", True);
   /* do error checking … */
   &retVal = &newField.Save();
   /* do error checking … */
End-If;

Syntax

SetTranslateValue(Translate_value,Active,EffDate,Long_name,Short_name)

Description

Use this method to add a new translate value or modify an existing value.

Parameters

Parameter

Description

Translate_value

Specifies the translate value as string.

Active

Specify a Boolean value whether the translate value is active or not.

EffDate

Specifies the effective date.

Long_name

Specifies the long name of the translate value as string

Short_name

Specifies the short name of the translate value as string

Returns

An integer representing the following statuses.

Numeric Value

Constant Value

Description

0

%MDA_Success

The translate values are updated.

1

%MDA_Failed

The translate values are not updated.

Example

Local FieldDefn &newField = CreateFieldDefn();
If All(&newField) Then
   &newField.Name = "MYNEWFIELD";
   &newField.Type = %FieldType_Char;
   &newField.Description = "My new field";
   &retVal = &newField.SetLabel("MYNEWFIELD", "My field", "My New Field", True);
   /* do error checking … */
   Local date &myDate = Date3(1900, 1, 1);
   &retVal = &newField.SetTranslateValue("A", True, &myDate, "My New XLAT", "My XLAT");
   /* do error checking … */
   &retVal = &newField.Save();
   /* do error checking … */
End-If;

Syntax

Validate()

Description

Use this method to validate a field definition.

Parameters

None.

Returns

A Boolean value. True if the field definition is successfully validated; false otherwise. If it returns false, the detailed error messages are available through the Messages property.

Example

Local FieldDefn &newField = CreateFieldDefn();
If All(&newField) Then
   &newField.Name = "MYNEWFIELD";
   &newField.Type = %FieldType_Char;
   &newField.Description = "My new field";
   &retVal = &newField.SetLabel("MYNEWFIELD", "My field", "My New Field", True);
   /* do error checking … */
   Local date &myDate = Date3(1900, 1, 1);
   &retVal = &newField.SetTranslateValue("A", True, &myDate, "My New XLAT", "My XLAT");
   /* do error checking … */
   &retVal = &newField.Validate();
End-If;