Monday, February 24, 2020

Table event handler in D365

Dataeventhandlers in table :

1. Create new class with final keyword, suffixed _Extension and add following method.
2. Decorate with ExtensionOf() attribute.

Example :

[ExtensionOf(tableStr(TableName)]

final class TableNameEventHandler
{

}

OnInserted eventhandler

[DataEventHandler(tableStr(TableName), DataEventType::Inserted)]

public static void TableName_onInserted(Common sender, DataEventArgs e)
{

    ValidateEventArgs   event       = e as ValidateEventArgs;
    TableName          localbuffer    =sender as TableName;       //get current record from sender

    //code here
}


Pre and Post eventhandlers in table :

Create any normal class and add following method.

Initvalue pre-eventhandler

// pre-event handler for initvalue
[PreHandlerFor(tableStr(TableName), tableMethodStr(TableName, initValue))]

public static void TableName_Pre_initValue(XppPrePostArgs args)
{
    TableName localbuffer = args.getThis() as TableName;    //get current record from args

    //code here
}

Initvalue post-eventhandler

//post-eventhandler for initvalue
[PostHandlerFor(tableStr(TableName), tableMethodStr(TableName, initValue))]
public static void TableName_Post_initValue(XppPrePostArgs args)
{
    TableName localbuffer = args.getThis() as TableName;      //get current record from args

    //code here
}

Monday, January 20, 2020

Error message in AX/D365 : Remove prefix in error message

In AX, prefix mechanism is used for precise error messaging about the transactions that an application performs. If required for your customization you do not wish to show the prefix text in error message we can achieve that using following :

This code will show error with prefix text :
throw error("Customer not found");
Output will be : 
someprefixedtext + Customer not found

This code will suppress prefix text :
throw infolog.add(Exception::Error, "Customer not found");
Output will be : 
Customer not found

All this happens in classmethod : Global\error.
infolog is global variable.


Tuesday, October 1, 2019

Open Web Page using X++ in Dynamics 365 FnO

To open web page we can use following code. It will also let you open url in new tab using parameter openInNewTab.

Browser browser = new Browser(); 
browser.navigate(str downloadUrl, [boolean openInNewTab], [boolean showExitWarning]);

Tuesday, August 13, 2019

Skip Validation for the data-entity mapped field

By using the following API, you can skip validation for a particular field, regardless of the consumer.

public void persistEntity(DataEntityRuntimeContext _entityCtx)
{
    this.skipDataSourceValidateField(fieldNum(_dataEntityName, _ dataEntityfield), true);
    super(_entityCtx);
}

_dataEntityfield - field ID of the data-entity mapped field, not the back-end table field.
_dataEntityName – name of data entity.

How to loop selected records on grid for form in dynamics ax?

To loop/iterate selected records from grid on form you can use following code, this can be done on clicked method of button control : Invent...