Friday, May 22, 2020

Code for insert, update and delete using Chain of Commands in D365 Finance & Operations

1:  [ExtensionOf(tableStr(Table1))]  
2:  final class Table1_Extension  
3:  {  
4:  	public void insert()  
5:  	{  
6:  		this.fieldName = “to insert”; //update field before insert method is executed  
7:  		next insert();  
8:  		this.fieldName = “to insert”; //update field after insert method is executed  
9:  	}  
10:  	public void delete()  
11:  	{  
12:  		//logic before delete method is executed  
13:  		next delete();  
14:  		//logic before after method is executed  
15:  	}  
16:  	public void update(anytype _parameters)  
17:  	{  
18:  		//logic before update method is executed  
19:  		next update(_parameters);  
20:  		//logic after update method is executed  
21:  	}  
22:  }  

Add action to Info/Error message in D365FnO

Starting in version 10.0.10 Platform update 34, you can use the Message::AddAction() method to embed an action within a message. This will help user to navigate through error on the form to update the data.
Example:
class TestJob_MenuAction
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        MenuItemMessageAction actionData = new MenuItemMessageAction();
        actionData.MenuItemName(menuItemDisplayStr(Inventsite));
        str jsonData = FormJsonSerializer::serializeClass(actionData);
        Message::AddAction(MessageSeverity::Error, "Site information required.", 'Site Master.', 
                           MessageActionType::DisplayMenuItem, jsonData);
    }
}
Output:
On click of Site Master, InventSite form will be opened.

Wednesday, April 8, 2020

Find Company details in Dynamics AX

Company Address:
CompanyInfo companyInfo = CompanyInfo::find();
info(strFmt("%1",companyInfo.postalAddress().Address));
Currency details:
CompanyInfo::standardCurrency() 

	OR

Ledger::accountingCurrency(CompanyInfo::current());

Wednesday, April 1, 2020

Monday, March 2, 2020

D365 finance & operations : SSRS reports deployment using windows powershell

To deploy reports using windows powershell, run Windows PowerShell as admin and use following commands :

To deploy all reports:

K:\AosService\PackagesLocalDirectory\Plugins\AxReportVmRoleStartupTask\DeployAllReportsToSSRS.ps1 -PackageInstallLocation “K:\AosService\PackagesLocalDirectory”

To deploy a specific report:

K:\AosService\PackagesLocalDirectory\Plugins\AxReportVmRoleStartupTask\DeployAllReportsToSSRS.ps1 -Module _SpecifyModuleName_ -ReportName _SpecifyReportName_ -PackageInstallLocation "K:\AosService\PackagesLocalDirectory"

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