Search

12 July 2018

Table method extension in AX 7 / D365

Below is the method created a new method in CustGroup table using extension concept in D365

[ExtensionOf(tableStr(CustGroup))]
Final class TRCustGroup_Extension
{
public Static void method1(CustGroup _custGroup)
{

info(strFmt("Table method using extension , Cust group id %1",_custGroup.CustGroup));
}

}

Table Events and Event handlers in AX 7 / D365

Below example is to create Pre and post event handler for Existing method and second method is a new override method in the CustGroup Table.
class TRCustGroupEventHandler
{

///
///
///

/// [PreHandlerFor(tableStr(CustGroup), tableMethodStr(CustGroup, delete))]
public static void CustGroup_Pre_delete(XppPrePostArgs args)
{
CustGroup custGroup = args.getThis() as CustGroup;
//custGroup.cut
}

///
///
///

/// /// [DataEventHandler(tableStr(CustGroup), DataEventType::ValidatingWrite)]
public static void CustGroup_onValidatingWrite(Common sender, DataEventArgs e)
{
CustGroup custGroup = sender as CustGroup;
}

///
///
///

/// /// [DataEventHandler(tableStr(CustGroup), DataEventType::ValidatedField)]
public static void CustGroup_onValidatedField(Common sender, DataEventArgs e)
{
CustGroup custGroup = sender as CustGroup;
ValidateFieldValueEventArgs ve = e as ValidateFieldValueEventArgs;
boolean ret = ve.parmValidateResult();

if(ret)
{
switch(ve.parmFieldName())
{
case fieldStr(CustGroup,CustGroup):
if(custGroup.CustGroup == "")
{
ret = false;
}
break;
}
}

ve.parmValidateResult(ret);
}
}

10 July 2018

How to get the postal address location name in AX 2012 / AX 7 / D365

Below is the code to get the location name:

LogisticsLocation::find(CustTable.postalAddress().Location).Description

How to Display Page Number in Report Body of SSRS / AX 2012 / AX 7 / D365

Go to "Report" -> "Report Properties" -> "Code"

In the Custom Code section, enter the following:

Public Function PageNumber() as String
Dim str as String
str = Me.Report.Globals!PageNumber.ToString()
Return str
End Function

Public Function TotalPages() as String
Dim str as String
str = Me.Report.Globals!TotalPages.ToString()
Return str
End Function


Body - Expression

="Page " + Code.PageNumber() + " of " + Code.TotalPages()

05 July 2018

D365: AX 7: Delegate - How to create and use delegate in Dynamics 365

D365: AX 7: Delegate - How to create and use delegate in Dynamics 365
How to return value in Deligate and Event handler methods.

class TestPrintMgmtDelegateHandler
{
///
///
///

/// /// [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
{
if (_result.result() != null)
return;

_result.result(VCPrintMgmtDelegateHandler::getDefaultReportFormat(_docType));
}

///
///
///

private static PrintMgmtReportFormatName getDefaultReportFormat(PrintMgmtDocumentType _docType)
{
#ISOCountryRegionCodes

switch(_docType)
{
case PrintMgmtDocumentType::SalesOrderInvoice:
if(SysCountryRegionCode::isLegalEntityInCountryRegion([#isoTH]))
{
return ssrsReportStr(VCDeliveryReport, Report);
}
}
return ssrsReportStr(SalesInvoice, Report);;
}

}

29 June 2018

Working with Queries 2 in AX 2012 and Dynamics 365

public Query queryBuild()
{
Query q;
QueryRun qr;
QueryBuildDataSource qbd,qbd1;

q = new Query();

qbd = q.addDataSource(TableNum(CustTable));
qbd1 = qbd.addDataSource(TableNum(CustTrans));
qbd1.addLink(fieldNum(CustTable, CustAccount), fieldNum(CustTrans, CustAccount));

return q;
}

public Query queryBuildHeader()
{
Query q;
QueryRun qr;
QueryBuildDataSource qbd,qbd1;

q = new Query();

qbd = q.addDataSource(TableNum(CustTable));

return q;
}

==
Query q = this.queryBuildHeader();

Table method extension in AX 7 / D365

Below is the method created a new method in CustGroup table using extension concept in D365 [ExtensionOf(tableStr(CustGroup))] Final clas...