Chain of command is used to write extension of code for a standard Table or Form which we need to be overwrite and make changes according to ours
Chain of command can be used in the following objects
1.Classes
2.Tables
3.Forms
4.Data source on a form.
5.Data field on a form.
6.Control of a form.
7.Data entities
Steps to Follow in COC
Step1: Name of the chain of command class we create must end with the _Extension.
Step2: The keyword ‘final’ must be used in the class definition line.
Step3: The class needs to have the attribute
[ExtensionOf(classStr(<NameOfBaseObject>))]
The “classStr” text above will change depending on the type of base objecting you are extending.
-> Below are the extensions used based on where we are using chain of commands.
-> When extending a class, use classStr(<NameofBaseClass>)
-> When extending a table, use tableStr(<NameOfBaseTable>)
-> In the case of a form, use formStr(<NameOfBaseForm>)
-> When extending a form Datasource use formDataSourceStr(<NameOfBaseForm>,<NameOfDataSource>)
-> When extending a form Data field, use formDataFieldStr(<NameOfBaseForm>,<NameOfDataSource>,<NameOfField>)
-> For a form control, use formControlStr(<NameOfBaseForm>,<NameOfControl>)
-> When extending a data entity, use tableStr(<NameOfBaseDataEntity>)
Step4: our code must call the base class’s method inside our extension method using the ‘next’ keyword. We need to have this line.
var s = next doSomething(arg);
** Example for form extension called SalesTable
Example 1 :
[ExtensionOf(formStr(SalesTable))]
final class SalesTable_Form_Extension
{
public void init()
{
next init();
//customize code goes here
}
}
Example 2:
[ExtensionOf(classStr(BusinessLogic1))] //name of the base class
final class BusinessLogic1_Extension //final keyword followed by class followed by baseobjectname _Extension
{
str doSomething(int arg)
{
// Part 1 // the logic which we write before next method will get execute first
var s = next doSomething(arg + 4);
// Part 2 The logic which we write after
return s;
}
}
Conclusion:
1) we can use Chain Of Command to add additional code before or after the call to the base method.
2) we still always have to call the base method. But we can change how the method works.
Comments
Post a Comment