31 July 2018

Converting time zones from Database time zone to Preferred time zone in AX 2012

utcDateTime Functionality in Dynamics AX 2012


utcDateTime localDateTime;

localDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());


Below is the reference link to get more idaa

26 July 2018

How to create contact for Customer or vendor in AX 2012 AX7 D365


DirParty dirParty;
DirPartyContactInfoView contact;
CustTable custTable;


custTable = CustTable::find(sfcCustRelation.AccountNum);
dirParty = DirParty::constructFromCommon(custTable);
contact.CountryRegionCode = CompanyInfo::find().DEL_CountryRegionId;
contact.LocationName = sfcCustRelation.Name;
contact.Locator = sfcCustRelation.EmailId;
contact.Type = LogisticsElectronicAddressMethodType::Email;
contact.ValidFrom = DateTimeUtil::getSystemDateTime();
//contact.ValidTo = DateTimeUtil::getSystemDateTime();//datetobeginUtcDateTime(1\1\2154, DateTimeUtil::getUserPreferredTimeZone()) ;
contact.Party = custTable.Party;
dirParty.createOrUpdateContactInfo(contact);

How to get contact informtaion for customer in AX 2012 AX 7 D365

CustTable custTable;
DirPartyTable dirParty;
LogisticsElectronicAddress electronicAddress;
DirPartyLocation dirPartyLoc;

//find the customer
custTable = CustTable::find("008");
//find the party for the customer
dirParty = DirPartyTable::findRec(custTable.Party);

//find all of the contacts for the current customer
while SELECT * FROM electronicAddress
EXISTS JOIN * FROM dirPartyLoc
WHERE electronicAddress.Location == dirPartyLoc.Location
&& dirParty.RecId==dirPartyLoc.Party
&& electronicAddress.Type == LogisticsElectronicAddressMethodType::Email
&& electronicAddress.Locator == "Test2Email@gmail.com"
{

info(electronicAddress.Locator);
}

23 July 2018

Dirparty table Contact person name Table structure and To make Contact person primary automatically for email in AX 2012 AX 7 D365


CustTable (Party)
DirPartyTable(RecId)
DirPartyLocation(Party)
LogisticsLocation(RecId)
LogisticsElectronicAddress(Location)



public void modified()
{
DirPartyLocation partyLocation;
LogisticsElectronicAddress electronicAddress;

super();


select partyLocation
where partyLocation.Party == custTable.Party &&
partyLocation.IsPrimary == true
exists join electronicAddress
where electronicAddress.Location == partyLocation.Location
&& electronicAddress.Type == LogisticsElectronicAddressMethodType::Email;


if( ! partyLocation.RecId)
{
DirPartyLocation_Electronic.IsPrimary = NoYes::yes;
}
else
{
DirPartyLocation_Electronic.IsPrimary = NoYes::No;
}

}

12 July 2018

Table method in extension AX 7 / D365 Extend the table in a new method / add a method in standard table in 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));
}
}
===========
[ExtensionOf(tableStr(InventTable))]
final class InventTable_Extension
{
    public static boolean isMyFieldEmpty(InventTable _this)
    {
        return _this.MyExtField == '' ? true : false;
    }

}

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

}

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...