Loading...

 Table event handler:


You need to add a new class to write the event handler methods. I would recommend adding one class to one table.

Once create table extension class must be declared above the class mention the attribute for purpose of the class


ExtensionOf(tableStr(TableName))]


ValidateField:



 // Table Dataeventhandler - ValidateField
 [DataEventHandler(tableStr(TableName), DataEventType::ValidatedField)]
 public static void TableName_onValidatedField(Common sender, DataEventArgs e)
 {
      ValidateFieldEventArgs  event   = e as ValidateFieldEventArgs ;
      TableName buffTable             = sender as TableName;
      boolean result                  = event.parmValidateResult();
 }




 // Table-Posteventhandler for validateField
  [PostHandlerFor(tableStr(TableName), tableMethodStr(TableName, validateField))]
  public static void TableName_Post_validateField(XppPrePostArgs args)
  {
      TableName buffTable = args.getThis();
      FieldId fieldId     = args.getArg("_fieldId");
      boolean ret         = args.getReturnValue();

      //pass the return value
      args.setReturnValue(ret);
  }




initValue:

// Table Post eventhandler for table initvalue
 [PostHandlerFor(tableStr(TableName), tableMethodStr(TableName, initValue))]
 public static void TableName_Post_initValue(XppPrePostArgs args)
 {
      TableName buffTable = args.getThis() as TableName;
 }


// Table pre-event handler for initvalue
 [PreHandlerFor(tableStr(TableName), tableMethodStr(TableName, initValue))]
 public static void TableName_Pre_initValue(XppPrePostArgs args)
 {
     TableName buffTable = args.getThis() as TableName;
 }



Insert:

// Table  - insert Dataeventhandler
 [DataEventHandler(tableStr(TableName), DataEventType::Inserted)]
 public static void TableName_onInserted(Common sender, DataEventArgs e)
 {
     ValidateEventArgs   event   = e as ValidateEventArgs;
     TableName buffTable         =sender as TableName;
 }




Update:

// Table-Posteventhandler for update
 [PostHandlerFor(tableStr(TableName), tableMethodStr(TableName, updateBackStatus))]
 public static void TableName_Post_updateBackStatus(XppPrePostArgs args)
 {
     TableName buffTable = args.getThis();
 }




ModifiedField:

// Table- pre-event handler for modified field
 [PreHandlerFor(tableStr(TableName), tableMethodStr(TableName, modifiedField))]
 public static void TableName_Pre_modifiedField(XppPrePostArgs args)
 {
     TableName buffTable = args.getThis() as TableName;

 }

// Table -post-event handler for the modified field
 [PostHandlerFor(tableStr(TableName), tableMethodStr(TableName, modifiedField))]
 public static void TableNamee_Post_modifiedField(XppPrePostArgs args)
 {
      TableName buffTable = args.getThis() as TableName;   
 }





Datasource event handler:

Written:

// Datasource - event handler for written
    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::Written)]
    public static void DataSourceName_OnWritten(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun         form              = sender.formRun();
        FormDataSource  DatasourceName_ds = form.dataSource(formDataSourceStr(FormName, DataSourceName)) as FormDataSource;
        TableName       buffTable         = DatasourceName_ds.cursor();
    }



initValue:

// Datasource - EventHandler for datasource initvalue
    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::InitValue)]
    public static void DataSourceNames_OnInitValue(FormDataSource sender, FormDataSourceEventArgs e
    {
        FormRun          formRun             = sender.formRun();
        FormDataSource   DataSourceName_ds   = formRun.dataSource(formDataSourceStr(FormName,DataSourceName)) as FormDataSource;
        TableName        buffTable           = DataSourceName_ds.cursor();
    }


Activated:

//Datasource - Event handler for data source activated method
    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::Activated)]
    public static void DataSourceName_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        DataSourceName buffDataSource = sender.cursor();  
        FormDataSource DataSourceName_ds = sender.formRun().dataSource("DataSourceName");
        FormRun element = sender.formRun();
    }



Init:

  // Datasource - event handler for data source init
    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::Initialized)]
    public static void DataSourceName_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormDataSource datasourceName_ds = sender.forRun().dataSource("DataSourceName");
        FormRun element = sender.formRun();
    }



ValidateWrite:
// DataSource - eventhandler for datasource validatewrite
    [FormDataSourceEventHandler(formDataSourceStr(FormName, DataSourceName), FormDataSourceEventType::ValidatingWrite)]
    public static void DataSourceName_OnValidatingWrite(FormDataSource sender, FormDataSourceEventArgs e)
    {
        var datasource = sender as FormDataSource;
        var args = e as FormDataSourceCancelEventArgs;
        if (args != null && datasource != null)
        {
            // write your own logic
        }
    }



Form event handler: 


OnInitialized:
// Form  - event handler for form OnInitialize
    [FormEventHandler(formStr(FormName), FormEventType::Initialized)]
    public static void FormName_OnInitialized(xFormRun sender, FormEventArgs e)
    {

        FormDataSource DataSourceName_ds = sender.dataSource(formDataSourceStr(FormName, DataSourceName));
            //Or
        FormDataSource DataSourceName_ds = sender.dataSource('DataSourceName');

    }



Closing:
   
// form- event handler for form closing
    [FormEventHandler(formStr(FormName), FormEventType::Closing)]
    public static void FormNamee_OnClosing(xFormRun sender, FormEventArgs e)
    {
        FormDataSource datasource_ds    = sender.dataSource(formDataSourceStr(FormName, DataSourceName));
        TableName      buffTable        = datasource_ds.cursor();
    }



Init:
// Form - event handler for form init.
    [PostHandlerFor(formStr(FormName), formMethodStr(FormName, init))]
    public static void FormName_Post_init(XppPrePostArgs _args)
    {
        FormRun form             = _args.getThis();
        FormDesign design        = form.design();
        FormControl variableName = design.controlName(formControlStr(FormName, controlName));
        FormControl variableName = design.controlName(formControlStr(FormName, controlName));
    }

Published on:

Learn more
Need help with this product?

We can help you with

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

Sherif Fayed
Sherif Fayed

Share post:

Related posts

D365 Sending Email with Customer Account Statement SSRS report as attachment using X++

D365 Sending Email with Customer Account Statement SSRS report as attachment using X++ custTable _custTable;        &...

2 years ago

clicking link on info message X++ to Open form

 Message::AddAction() method can be used to embed an action within a message sent to the message bar. This method supports adding a singl...

2 years ago

D365 FO - Send Email with attachments by X++

 Go to System administration >> Setup >> Email >> System email templatesCreate New template [ExtensionOf(clas...

2 years ago

D365 FO Data entity Export using X++

This post provides information on exporting data entity through X++ in D365 FO. The post includes a code snippet written in X++ that can be us...

2 years ago

D365 FO Encryption And Decryption Using A Symmetric Key(AES) using X++

If you're looking to encrypt and decrypt data using a symmetric key in D365 FO, this tutorial is the right place to be. The post details the s...

2 years ago

Get multiple selected rows using D365 X++

This blog post offers a valuable insight into D365 X++, offering a detailed guide on how to get multiple selected rows. Multi-select for Butto...

2 years ago

D365 Solution for Cloud Dev machine show error ' The remote certificate is invalid according to the validation procedure. '

 You are getting 'The remote certificate is invalid according to the validation procedure.'Error show with all reports and  tired Ro...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.