How to do it...

To write a form extension for the sales order form, SalesTable, follow these steps:

  1. Locate the desired form in the Application Explorer, right click on it and choose Create extension. This will add a new form extension to our project.
  2. Locate the new form extension in our project, and rename it so it will remain globally unique, for example, SalesTable.Con.
  3. Open the form extension in the designer.
  4. We can now drag any field or field group, including extension fields that are available to the current package, to the design.
  5. We can also choose to change properties of the controls on the form's design. The rule here is that, if it lets you change, it will work.
Remember that whilst doing this, all changes should be at the lowest level possible as this ensures consistency and minimizes maintenance effort.

This covers the design, but not the code. We can right-click on most methods and use Copy event-handler method to create a pre-event or post-event handler. This may suffice in some cases, but we can go further. In the November update, we can now create extension classes that act as an extension to the form's code.

The following example explains one of the many benefits that may not immediately be obvious.

To create an extension class for a form's code, follow these steps:

  1. Create a new class that must end in _Extension; so, for a SalesTable extension, use ConSalesTable_Extension.
For this to work, we only need to have the ExtensionOf decoration and ensure that the name ends in _Extension.
  1. The class declaration should read as follows:
[ExtensionOf(formStr(SalesTable))] 
final class ConSalesTable_Extension
  1. In this example, we will determine the caller record by handling the initialized event and use the stored record that is scoped to the form when we close the form. The code for this is as follows:
[ExtensionOf(formStr(SalesTable))] 
final class ConSalesTable_Extension
{
Private CustTable conCustTable;
[FormEventHandler(formstr(SalesTable),
FormEventType::Initialized)]
public void initializedFormHandler(xFormRun formRun,
FormEventArgs e)
{
Args args = formRun.args();
switch(args.dataset())
{
case tableNum(CustTable):
conCustTable = args.record();
break;
}
}
[FormEventHandler(formstr(SalesTable),
FormEventType::Closing)]
public void initializedFormHandler(xFormRun formRun,
FormEventArgs e)
{
if(conCustTable.RecId != 0)
{
if(FormDataUtil::isFormDataSource(
conCustTable))
{
FormDataUtil::getFormDataSource(
conCustTable).research(true);
}
}
}
}
We do not normally prefix variables in our own code, but in the preceding case we prefixed CustTable with Con. The extension class is like a decoration, and the variables we create must be unique in the scope of the form instance.

If you want to write a method to override a form-control event, just as a modified event of ItemId, we will perform the following steps:

  1. Add the following lines to the initializedFormHandler method created earlier:
FormDataObject itemIdDataObject; 
itemIdDataObject = this.SalesLine_DS.object(
fieldNum(SalesLine, ItemId), 1);

itemIdDataObject.registerOverrideMethod(
methodStr(FormDataObject, modified),
methodStr(ConSalesTable_Extension,
modifiedItemIdHandler), this);
  1. Then add the override handler, as follows:
/// <summary> 
/// Handles the modified event of the
/// ItemId data source field
/// </summary>
/// <param name = "itemIdFieldObject"></param>
public void modifiedItemIdHandler(
FormDataObject itemIdFieldObject)
{
// write what should happen here
}
FormDataObject has the settings for the data source field, such as AllowEdit. It also has a dataSource() method to fetch the FormDataSource object. This would be needed if the method didn't already have access to the form's data sources, which it does, as they are declared public.
  1. This is it. We should experiment and get used to this paradigm before using it for real.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.161.92