12 July 2018

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();

07 June 2018

How to get user input value in Controller class in AX 2012 D365


How to get user input value in Controller class in AX 2012 D365
How to get contract value and based on the user value condition run report design

class TestController extends SrsReportRunController
{
public static void main(Args _args)
{
TestController controller = new TestController();
controller.parmReportName(ssrsReportStr(StatementMan, report));
controller.parmArgs(_args);
controller.startOperation();
}

///
///
///

protected void preRunModifyContract()
{
TestStmtContract contract = this.parmReportContract().parmRdpContract() as TestStmtContract;
this.parmReportContract().parmReportName(this.getReportName(contract));
super();
}

private str getReportName(TestStmtContract _contract)
{
str reportNameLocal;

if (_contract.parmNoTrans()) // this is the user input value
{
reportNameLocal = ssrsReportStr(StatementMan, report1);
}
else
{
reportNameLocal = ssrsReportStr(StatementMan, report);
}

return reportNameLocal;
}

}

Service class to get the selected record and deleted matching records and refresh the form data source in D365 F&O

 [DataContractAttribute] class ABCUserProfilesBulkDeleteContract {         UserId userId;     [DataMemberAttribute('UserId')]     pu...