Showing posts with label AX2012. Show all posts
Showing posts with label AX2012. Show all posts

Settle Clearing Entries (Postdated Check) Status



Settle Clearing Entries (Postdated Check) Status



Recently I face the issue that after posting of payment journal status of a post-dated check was not changed from Open to Post. I have lots of R&D in this but no luck,

So I write a batch job where will change the status of custVendPosted check for me.






    LedgerJournalTable _ledgerJournalTable;
    LedgerJournalTrans _ledgerJournalTrans;
    CustVendPDCRegister custPDC;
    Counter             _counter=0;

    while select forUpdate custPDC
            where custPDC.PDCStatus==PostDatedCheckStatus::Open
            && custPDC.MaturityDate > systemDateGet()
          exists join _ledgerJournalTrans
            where custPDC.LedgerJournalTrans==_ledgerJournalTrans.RecId
          exists join _ledgerJournalTable
            where _ledgerJournalTrans.JournalNum==_ledgerJournalTable.JournalNum
            && _ledgerJournalTable.Posted==NoYes::Yes
    {
               _counter++;
               custPDC.PDCStatus=PostDatedCheckStatus::Posted;
               ttsBegin;
               custPDC.update();
               ttsCommit;

    }
        info(strFmt("Total Number %1 of records updated on %2.",_counter,today()));


Create Contact Person for Vendor Or Customer AX 2012 & D365FO



Create Contact Person for Vendor Or Customer AX 2012 & D365FO



Important

In D365FO use ContactPersonSyncEntity class and in AX 2012 use ContactPersonEntity 



Using below code you can create contact person against Customer or Vendor in AX 2012 & D365FO.





class SLD_DemoInstance
{





    
    public static void main(Args _args)
    {

        // Declare variables: views.
        DirPartyContactInfoView contactInfo;
        DirPartyPostalAddressView postalAddress;

        // Declare variables: tables.
        ContactPerson contactperson;

        DirPartyTable partyTable = DirPartyTable::findRec(VendTable::find("S00038").Party);
   
        // Declare variables: classes.
        ContactPersonEntity contactPersonEntity;

   

  
        // Create and populate the contact person.

        contactPersonEntity = ContactPersonEntity::construct(contactPerson);
      
        contactPersonEntity.parmFirstName("FirstName");
        contactPersonEntity.parmMiddleName('M.');
        contactPersonEntity.parmLastName('Person');
        contactPersonEntity.parmAssistantName('AssistantName');
        contactPersonEntity.parmBillingInformation('Billing info');
        contactPersonEntity.parmCharacter('Character description');
        contactPersonEntity.parmComputerNetworkName('Computer network name');
        contactPersonEntity.parmContactForParty(partyTable.RecId);
        contactPersonEntity.parmContactMemo('Memo');
        contactPersonEntity.parmContactPersonId('CP64');
        contactPersonEntity.parmLoyalty('Loyalty');
        contactPersonEntity.parmMileage('Mileage');
        contactPersonEntity.parmOfficeLocation('Office location');
        contactPersonEntity.parmOutlookCategories('Outlook categories');
        contactPersonEntity.parmProfession('Profession');
        contactPersonEntity.parmSensitivity(smmSensitivity::Personal);
        contactPersonEntity.parmSpouse('Spouse');
        contactPersonEntity.parmTimeAvailableFrom(1000);
        contactPersonEntity.parmTimeAvailableTo(2000);
        contactPersonEntity.write();

        // Populate the postal address information by using the view.
        postalAddress.clear();
        postalAddress.Street = 'One Microsoft Way';
        postalAddress.City = 'Redmond';
        postalAddress.State = 'WA';
        postalAddress.ZipCode = '98052';
      
        postalAddress.Address="QAR";
        postalAddress.CountryRegionId = "Country Region ID";


        // Update the postal address information.
        contactPersonEntity.createOrUpdatePostalAddress(postalAddress);


        //phone

        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="Phone";
        contactInfo.Locator = "123456";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Phone;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);




      
        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="Email";
        contactInfo.Locator ="abcd@gmail.com";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Email;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);



        contactInfo.clear();
        //Populate the contact information by using the view.
        contactInfo.LocationName="FAX";
        contactInfo.Locator ="98798789798";
        contactInfo.Type = LogisticsElectronicAddressMethodType::Fax;
        contactInfo.IsPrimary = true;
        // Update the contact information.
        contactPersonEntity.createOrUpdateContactInfo(contactInfo);

    }

}

How to get Vendors or Customer Contact Information Primary & None Primary




 How to get Vendors or Customer  Contact Information Primary & None Primary



Via below code you can get the Vendor/Customer complete contact information (Primary & None Primary).

  LogisticsElectronicAddress logisticsElectronicAddress;
        DirPartyLocation        dirLocation;
        DirPartyTable dirPartyTable=DirPartyTable::findRec(VendTable::find("S00038").Party);
     
        while select  logisticsElectronicAddress
        join dirLocation  where dirLocation.Location==logisticsElectronicAddress.Location
            && dirLocation.Party==dirPartyTable.RecId
        {
            info(strFmt("%1",logisticsElectronicAddress.Locator));
        }

How to get Vendor's or Customer's Contact Person's Contact Information




How to get  Vendor's or Customer's  Contact Person's Contact Information

Via below code you can get the Vendor/Customer contact person and their complete contact information.


class SLD_DemoInstance
{





   
    public static void main(Args _args)
    {

        ContactPerson            contactPerson;
        DirPartyTable       dirPartyTable;
        LogisticsElectronicAddress      address;
   
        DirPartyLocation        partylocation;
   
   
        RecId _refRecId= VendTable::find("S00038").Party;
        while select contactPerson
         where contactPerson.ContactForParty==_refRecId
        join dirPartyTable
        where dirPartyTable.RecId==contactPerson.Party
        join partylocation
        where partylocation.Party==contactPerson.Party
        outer join address
        where address.Location==partylocation.Location
      
        {
       
            info(strFmt("%1, %2, %3",contactPerson.ContactPersonId,contactPerson.personName(),address.Locator));
        }
    }


}




How to get Contact Person of Vendor & Customer



How to get Contact Person of Vendor & Customer 


Via below code you can retrieve the contact person list of vendor or customer


class SLD_DemoInstance
{

   
    public static void main(Args _args)
    {

        ContactPerson            contactPerson;
        DirPartyTable       dirPartyTable;
   
        RecId _refRecId= VendTable::find("S00038").Party;
        while select contactPerson
        where contactPerson.ContactForParty==_refRecId
        {
       
            info(strFmt("%1, %2",contactPerson.ContactPersonId,contactPerson.personName()));
        }
    }

}

How to get Vendors or Customer Primary Contact Information




How to get Vendors or Customer Primary Contact Information

Via below code you can get the Vendor/Customer complete contact information.

Important 
In AX 2012 PrimaryContactLinkedInPrimaryContactFacebook fields are not available.

class SLD_DemoInstance
{
   
    public static void main(Args _args)
    {

        LogisticsElectronicAddress logisticsElectronicAddress;
        DirPartyTable dirPartyTable=DirPartyTable::findRec(VendTable::find("K-DR-000001").Party);
     
        while select  logisticsElectronicAddress where (logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactEmail ||
            logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactPhone || logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactFacebook ||
            logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactFax || logisticsElectronicAddress.RecId == dirPartyTable.PrimaryContactLinkedIn)

        {
            info(strFmt("%1",logisticsElectronicAddress.Description));
        }
    }


}




Item Attribute



Item Attribute
Query relation to getting Item attributes.




InventTable                                             objinventTable;
EcoResProduct                                        objecoResProduct;
EcoResValue                                           objecoResValue;
EcoResAttributeValue                             objecoResAttributeValue;
EcoResAttribute                                      objecoResAttribute;
EcoResInstanceValue                              objecoResInstanceValue;
EcoResAttributeType                              objecoResAttributeType;
EcoResProductInstanceValue                 objecoResProductInstanceValue;
int i = 0;
;
while select objecoResAttributeValue
join objecoResAttribute
where objecoResAttributeValue.Attribute == objecoResAttribute.RecId
join objecoResAttributeType
where objecoResAttribute.AttributeType == objecoResAttributeType.RecId
join objecoResInstanceValue
where objecoResAttributeValue.InstanceValue == objecoResInstanceValue.RecId
join objecoResValue
where ecoResAttributevalue.Value == objecoResValue.RecId
join objecoResProductInstanceValue
where objecoResInstanceValue.RecId == objecoResProductInstanceValue.RecId
join objecoResProduct
where objecoResProduct.RecId == objecoResProductInstanceValue.Product
join objinventTable
where objinventTable.Product == objecoResProduct.RecId
&& objinventTable.itemid='D0001'
{
     info(strFmt("%1 %2",objecoResProduct.DisplayProductNumber,objecoResAttribute.Name));
}

Default Dimension D365FO AX-2012


Default Dimension D365FO AX-2012





Following Code will help you to create Default Dimension using X++



Default Dimension Class 


public class DefaultDimesnionHelper
{

    public static DimensionDefault createDefaultDimension(container conAttribute,container attributeValue)
    {
        DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
        DimensionDefault                    result;
  
        int                     i;
        DimensionAttribute      dimensionAttribute;
        DimensionAttributeValue dimensionAttributeValue;
  
        // Note that "Item" is not one of the default dimension,
        // but DimensionAttributeValueSetStorage will handle it gracefully
        container               conAttr = conAttribute;
        container               conValue = attributeValue;
        str                     dimValue;
  
        for (i = 1; i <= conLen(conAttr); i++)
        {
            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
      
            if (dimensionAttribute.RecId == 0)
            {
                continue;
            }
      
            dimValue = conPeek(conValue,i);
      
            if (dimValue != "")
            {
                // The last parameter is "true". A dimensionAttributeValue record will be created if not found.
                dimensionAttributeValue =
                    dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
          
                // Add the dimensionAttibuteValue to the default dimension
                valueSetStorage.addItem(dimensionAttributeValue);
            }
        }
  
        result = valueSetStorage.save();
        return result;
    }


}

Map Enumerator VS Map Iterator D365FO



Map Enumerator VS Map Iterator



Map Enumerator

Map enumerators are automatically created on the same tier as the map when you call the Map.getEnumerator method.

Using the MapEnumerator class avoids a potential problem in code marked as Called from, where the iterator and map can end up on separate tiers
Map enumerators require less code than map iterators, they perform slightly better.

Map Iterator

Map Iterator should be used when you want to delete items from a list by using the MapIterator.delete method.

Bar Code in SSRS Report D365FO


Bar Code in SSRS Report D365FO


Following are the simple steps to generate Bar-Code in SSRS report.

In SSRS temporary table, Bar-Code filed should be extended with BarCodeString EDT.

Use font >BC C128 Narrow

Field in SSRS should be well space otherwise bar-code scan will not work

Using following code you can generate bar-code of any value...

Example: xyzTableBuffer.BarCodeField= this.getBarcode("123456789")


    public str getBarcode(str _barCodeText)
    {
        BarcodeCode128 barcode;

        barcode = Barcode::construct(BarcodeType::Code128);
        barcode.string(true, _barCodeText);
        barcode.encode();

        return barcode.barcodeStr();
    }



Please feel free to contact me if you are facing any issue during implementation of the blog

Record sorting D365FO, AX 7 and AX-2012


Record sorting D365FO, AX 7 and AX-2012


Today, I got requirement to perform sorting on form with table data source while inserting records..



SLDOffsetTaxDS_DS.query().dataSourceName(formDataSourceStr(SLDOffsetTax,SLDOffsetTaxDS)).addSortField(fieldNum(SLDOffsetTax, Priority), SortOrder::Ascending);

SLDOffsetTaxDS_DS.query().dataSourceName(formDataSourceStr(SLDOffsetTax,SLDOffsetTaxDS)).addSortField(fieldNum(SLDOffsetTax, CountryRegionId), SortOrder::Ascending);

Batch job Execution for ALL Companies



Batch job Execution for ALL Companies

void run()
{
while select crossCompany purchTable

{

    changeCompany(purchTable.DataAreaId)

{
// todo your logic
}

}

}

Flush the AOS cache from code. AX-2012

Flush the AOS cache from code.  AX-2012 


Well while working on a old project my project lead shared with me a very nice little trick. 


Well the trick is to copy these three menu items, and then change the run from property to server. Now you can launch these menu items, and they will run on the server, therefore clearing the AOD, sys data, and dictionary, causing a refresh. 

Menu item you can find on the below path
[Under Menu items > Action]

  1.  SysFlushAOD
  2.  SysFlushData
  3.  SysFlushDictionary

New Report or new Design of Existing Report in Print Management


New Report or new Design of Existing Report  in Print Management 


The simple way to add a new report or new design of an existing report in Print management 


Step-1 Create a new class SLD_DemoSample


Step-2 Find class PrintMgmtDocType in Application Explore and open in the designer 



Step-3 find the delegate in PrintMgmtDocType class  Delegate name is  getDefaultReportFormatDelegate



Step-4 Subscribe to the event of above-highlighted event in the newly created class


Step-5 Now add your report design in the EventHandlerResult _result


  /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        if(PrintMgmtDocumentType::CustInterestNote==_docType)
        {
            _result.result(ssrsReportStr(SLD_BinCart,Report));

        }
      
    }


Step-6 Perform build and sync and verify on D365FO

Feel free to contact me if you are facing any issues during the implementation of this blog.








Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...