How to use MessageNumber and MessageSetNumber with ExecuteEdits

The ExecuteEdits method in Record Object executes the standard system edits on every field in the record. standard system edits are;
  • Reasonable Date Range (Is the date contained within the specified reasonable date range?)
  • Required fields are present
  • Validates all 1/0 fields contain only a 1 or a 0
  • Validates all translate fields have a valid value
  • Validates all YesNo fields contain a Y or an N
  • Validates all prompt edit fields have a valid value
If any of the edits fail, which means an error has found for any field, the status of the property IsEditError is set to True for the record. Then, we can use Field class properties EditError to find out which field is in error, and MessageSetNumber and MessageNumber field class properties to find the error message set number and error message number.
This kind of validation is useful in Application Engine programs or if you executing Component Interfaces (CI) via PeopleCode.
One way of doing this is before you assign values to the real record (SQL record) you can create a copy of the real record as a derived/work record. Then you can invoke ExecuteEdits method with the derived record to check any standard system edits.  

As an example;

Function executePromptTableEdit() Returns boolean;
 Local number &msgnum, &msgset;
   Local integer &i;
   Local string &msgtxt;
   &WorkRec = CreateRecord(Record.MY_DERIVED_RECORD);
   &WorkRec.SetDefault();
   
   /* Copying like-named field values from SQL record to the derived record */
   &REC = GetRecord(RECORD.MY_SQL_RECORD);
   &REC.CopyFieldsTo(&WorkRec);
   
   /*  all system edits are executed */
   &WorkRec.ExecuteEdits();
   
   /* If edit error found */
    If &WorkRec.IsEditError Then
     For &i = 1 To &WorkRec.FieldCount
       If &WorkRec.GetField(&i).EditError Then
        &msgnum = &WorkRec.GetField(&i).MessageNumber;
        &msgset = &WorkRec.GetField(&i).MessageSetNumber;
        &msgtxt = MsgGetText(&msgset, &msgnum, "Message not found", "");
        /* here you can push this informaton to an Array and later you can use this array to populate error information to a Message Record for further lookup*/
       End-If;
     End-for;
     Return False;
    end-If; 
  Return True;  
end-function;

This way, you can use ExecuteEdit method to get the field edit error information for your next application.
SHARE

Ayesha Wee

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment