Return to Navigation

Writing Custom Logic for Validation and Formatting

On the Common Attribute page, it is possible to associate formatting and validation logic with an attribute. If the delivered list of attribute format options is not sufficient, you can write your own application class with custom logic and associate that class with the attribute on the Common Attribute page.

The custom class must extend the interface SCC_COMM_ATTRIBUTE_FW:Interfaces:iAttributeModifier.

This interface has two methods: Validate and Format.

Validate method:

Write PeopleCode in this method that will validate the data in the attribute. The framework invokes this method when the user tabs out of the attribute field after entering a value or clicks the Save button after entering the attribute value. If you want to display a message, populate the &p_msg object with the required message. The framework shows this message when the user tabs out of the attribute field after entering a value or clicks the Save button after entering the attribute value. The framework picks the severity of the message from the message catalog entry’s severity.

Here is the sample code for populating the &p_msg object.

method validate

   /+ &p_value as Any, +/

   /+ &p_msg as SCC_COMMON:ENTITY:LOG:MessageLogBase out +/

   /+ Returns Boolean +/

   /+ Extends/implements 

SCC_COMMON_ATTRIBUTE_FW:Interfaces:iAttributeModifier.validate +/
   
   Local SCC_COMMON:ENTITY:LOG:MessageLogBase &msg = 
create SCC_COMMON:ENTITY:LOG:MessageLogBase();

   Local SCC_COMMON:ENTITY:LOG:MessageEntry &me;
   
   If Len(String(&p_value)) >= 3 Then

      Local Record &rec = CreateRecord(Record.COUNTRY_TBL);

      &rec.COUNTRY.Value = String(Substring(&p_value, 1, 3));

      If &rec.SelectByKey() Then

         Return True;

      Else

         &me = create SCC_COMMON:ENTITY:LOG:MessageEntry();

         &me.MsgSet = 14098;

         &me.MsgID = 10;

         &me.Severity = &me.Severity_Error;

         &msg.writeEntry(&me);

         &p_msg = &msg;

         Return False;

      End-If;

   Else

      &me = create SCC_COMMON:ENTITY:LOG:MessageEntry();

      &me.MsgSet = 14098;

      &me.MsgID = 11;

      &me.Severity = &me.Severity_Error;

      &msg.writeEntry(&me);

      &p_msg = &msg;

      Return False;

   End-If;

   end-method;

The return value of this method indicates if the validation passed or failed. If the return value is True, then the framework assumes that the validation has passed and will continue processing. But if the return value is False, the framework halts processing and displays the messages if any in the &p_msg object. Based on the severity of the message, the user is either forced to make changes to the attribute data (severity error) or just dismiss the message and continue with other attributes on the page.

Format method

The framework invokes this method on fieldchange event. Write PeopleCode in this method that will format the attribute value. The framework then displays the formatted value on the page.

Here is an example of formatting an attribute value to appear as a US zip code.

method format

   /+ &p_value as Any +/

   /+ Returns String +/

   /+ Extends/implements 
SCC_COMMON_ATTRIBUTE_FW:Interfaces:iAttributeModifier.format +/

   Local string &str = String(&p_value);

      If Len(&str) = 9 Then

      Return (Substring(&str, 1, 5) | "-" | Substring(&str, 5, 4));

   Else

      Return &str;

   End-If;

end-method;