Loading...

D365 Table event methods

D365 Table event methods

 

Here are quick examples of the most important event methods on a table,
class Dpk_VendTableEventHandlerClass
{
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::InitializedRecord)]
public static void VendTable_onInitializedRecord(Common sender, DataEventArgs e)
{
VendTable vendTable = sender as VendTable;
vendTable.VendGroup = "VG001"; //Change this value
//Add business logic
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::Inserted)]
public static void VendTable_onInserted(Common sender, DataEventArgs e)
{
VendTable vendTable = sender as VendTable;
if(!vendTable.YourAccountNum)
{
//Add business logic
vendTable.YourAccountNum = "This is event handler example";
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::Deleted)]
public static void VendTable_onDeleted(Common sender, DataEventArgs e)
{
VendTable vendTable = sender as VendTable;
//Add business logic
if (box::yesNo(strFmt('The selected vendor with Rating %1 will be deleted, are you sure ?', vendTable.CreditRating), dialogButton::Yes, 'Confirmation') == dialogButton::Yes)
{
Info("Operation successfull");
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::ValidatingWrite)]
public static void VendTable_onValidatingWrite(Common sender, DataEventArgs e)
{
VendTable vendTable = sender as VendTable;
//Add business logic
if((vendTable.CreditMax && !vendTable.CreditRating)
|| (!vendTable.CreditMax && vendTable.CreditRating))
{
warning("Credit rating must filled for credit limit");
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::ModifiedField)]
public static void VendTable_onModifiedField(Common sender, DataEventArgs e)
{
ModifyFieldEventArgs event = e as ModifyFieldEventArgs;
VendTable vendTable = sender as VendTable;
FieldId fieldId = event.parmFieldId();
switch(fieldId)
{
//Add business logic
case fieldNum(VendTable, PaymMode):
Info("Business logic for PaymMode");
break;
default:
break;
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(VendTable), DataEventType::ValidatingField)]
public static void VendTable_onValidatingField(Common sender, DataEventArgs e)
{
VendTable vendTable = sender as VendTable;
ValidateFieldEventArgs validateFieldEventArgs = e as ValidateFieldEventArgs ;
boolean ret = validateFieldEventArgs.parmValidateResult();
if(ret)
{
switch(validateFieldEventArgs.parmFieldId())
{
//Add business logic
case fieldNum(VendTable, CreditMax):
if(vendTable.CreditRating == "Amber" && vendTable.CreditMax > 10000)
{
vendTable.CreditMax = 0;
Error("Credit can not exceed more than 10K for Amber rating");
ret = false;
}
break;
}
}
validateFieldEventArgs.parmValidateResult(ret);
}
}

Reference 

Published on:

Learn more
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.