GetField method: Record class

Syntax

GetField({n | FIELD.fieldname})

Description

The GetField method instantiates a field object for the specified field associated with the record. This is the default method for the record object. This means that any record object, followed by a parameter list, acts as if GetField is specified.

Note:

If the field you’re accessing has the same name as a record property (that is, Name or FieldCount) you can’t use the default method for accessing the field. You must specify GetField.

For example, the following is invalid for accessing the value of a field called NAME:

&NUMBER = &REC.NAME.Value;

You must use the following code to get the value of a field called NAME:

&NUMBER= &REC.GetField(FIELD.NAME).Value;

Parameters

Parameter Description

n | FIELD.fieldname

Specify a field to be used for instantiating the field object. You can specify either n or FIELD. fieldname. Specifying n creates a field object for the nth field in the record. This might be used if writing code that needs to examine all fields in a record without being aware of the name. Specifying FIELD. fieldname creates a field object for the field fieldname.

Note:

There is no way to predict the order the fields will be accessed. Use the n option only if the order in which the fields are processed doesn’t matter.

Returns

A field object.

Example

&REC.GetField(FIELD.CHARACTER).Value = "Hello";

As GetField is the default method for a record object, the following code is identical to the previous code:

&REC.CHARACTER.VALUE = "Hello";

The following code creates an array containing all the names of all the fields in a related language record.

Local array of string &FIELD_LIST_ARRAY;
&FIELD_LIST_ARRAY = CreateArray();
For &I = 1 to &REC_RELATED_LANG.FieldCount
   &FIELD_LIST_ARRAY.Push(&REC_RELATED_LANG.GetField(&I).Name);
End-For;

The GetField method requires either FIELD.fieldname or a number. It won’t take a string field name. However, you can use the @ operator to convert the string field name into a FIELD.fieldname reference, as follows:

&REC = GetRecord();
&REC2 = GetLevel0(1).EMPL_CHECKLIST;
&FIELD2 = &REC.GetField(@ "FIELD." | &REC2.getfield(&I).Name);

The following code converts field name strings (using the @ symbol) to component names to get the value of all the fields in a subrecord. Note the code in Keyword style.

Function get_draft_dst_codes
   /* Load dst id codes into record structures */
   &DSTCODES = CreateRecord(RECORD.DR_DST_CODE_SBR);
   &DRAFTITEM = GetRecord(RECORD.DRAFT_ITEM);
   &DRAFTITEM.CopyFieldsTo(&DSTCODES);
   /* If any missing get from AR dist code, then Draft Type-BU, then BU */
   For &I = 1 To &DSTCODES.FieldCount
      If None(&DSTCODES.GetField(&I).Value) Then
         get_ar_dst_code();
         &NAME = &DSTCODES.GetField(&I).Name;
         If All(&DST.GetField(@ ("FIELD." | &NAME)).Value) Then
            &DSTCODES.GetField(&I).Value = &DST.GetField(@("FIELD." |⇒
 &NAME)).Value;
         Else
            If All(&R_DRAFTBU.GetField(@("FIELD." | &NAME)).Value) Then
               &DSTCODES.GetField(&I).Value = &R_DRAFTBU.GetField(@("FIELD." |⇒
 &NAME)).Value;
            Else
               &DSTCODES.GetField(&I).Value = &R_ARBU.GetField(@("FIELD." |⇒
 &NAME)).Value;

            End-If;
         End-If;
      End-If;
   End-For;
   /* Copy the defaulted values back to draft item */
   &DSTCODES.CopyFieldsTo(&DRAFTITEM);   
End-Function;