Wednesday, January 4, 2012

How to Implement the xSysLastValue pattern

Recently, i have experienced to implement the xSysLastValue to resolve a problem.

The problem was to restore that value of the control (set by the user), that was not binded to the table. That was the string edit control, lookup method populated the control and an edit method is used get/set the value.
There is a class xSysLastValue is used to implemented the pattern which used SysLastValue table to store the usuage data specific to a users navigate the system. such as report selections, query ranges and form

There are some methods that should overrided in order to implement the pattern.

//The user ID of the current user.
private UserId lastValueUserId(){
    return curUserId();
}


/// An object <c>UtilElementType</c> type defining the type of object.
private UtilElementType lastValueType(){
    return UtilElementType::Form;
}


/// An object of <c>Identifiername</c> type that determines the name of the object.
private IdentifierName lastValueElementName()
{
    // If i implemented it on form, form name should be given here
    return this.name();
}


/// An object of <c>Identifiername</c> type that determines the design name of the object.
private IdentifierName lastValueDesignName()
{
    // Here the value should be the value that is unique for that record
    // In my form BudgetPlanheaer is a master table, so its Id is unique
    return strfmt("%1", budgetPlanHeader.RecId);
}


/// An object of <c>DataAreaID</c> type that determines the data area ID.
DataAreaId lastValueDataAreaId()
{
    return curext();
}


/// Initializes default value of the project basis source group.
void initParmDefault()
{
    budgetSourceOn = ProjBaseBudgetOn::Entry;
}


In class declaration you need to specify variables in localmacro for the variables whose values needs to required and define the pack/unpack methods

#define.CurrentVersion(1)
#localmacro.CurrentList
   budgetPlanScenarioValue
#endmacro


public container pack()
{
    this.getBudgetScenarioLookupControl();

    return [#CurrentVersion, #CurrentList];
}


public boolean unpack(container packedClass)
{
    Integer version = conPeek(packedClass, 1);

    switch (version)
    {
        case #CurrentVersion:
            [version, #CurrentList] = packedClass;
            break;

        default:
            return false;
    }

    return true;
}


Called the  xSysLastValue::getLast(forms object in this case) method to get the last state of the object. The point that is important here that the method should be called when the value that is specified on lastValueDesignName is populated, I have called in on the datasource active method as xSysLastValue::getLast(element) because i was using the buffer of datasource.
After restoring the values, you just need to assign it to the controls and do further actions upon it, Save the value on the variable whenever the control value is modified.


/// Saves value of form controls in the <c>xSysLastValue</c> before closing the form.
public void close()
{
    super();

    xSysLastValue::saveLast(this);
}


 

No comments:

Post a Comment