Tuesday, 9 August 2022

Add address to Customer AX 2012 X ++

 //How to create a new customer address using x++ code

static void MK_createCustomerAddress(Args _args)

{

    LogisticsPostalAddress address;

    LogisticsLocation       location;

    LogisticsAddressCountryRegion conuntry;

    LogisticsAddressState           state;

    DirPartyPostalAddressView   addressView;

    DirPartyLocation    partylocation;

    DirParty dirParty;

    DirPartyTable   dirPartyTable;

    CustTable   custTable;

    container  roles;

    LogisticsPostalAddressEntity    postalAddressEntity;

    LogisticsPostalAddressView      paddressView;

    date dVF,dvt;


    select custTable

          join  dirPartyTable where custtable.Party ==   dirPartyTable.RecId

          //join  location where dirPartyTable.PrimaryAddressLocation == location.RecId

                                //&& location. == "Mrs Carol Davis"

           //join  address  where address.Location == location.RecId

        && custtable.AccountNum == "C012436877";

    if (dirPartytable.RecId)

    {

        conuntry = LogisticsAddressCountryRegion::findByISOCode('GB');

        //state = LogisticsAddressState::find(conuntry

        location.Description = 'Mr paddressView';

        location.IsPostalAddress = true;

        location.insert();

        address.Street = "Mr paddressView 909 Market St 3";

        address.ZipCode = "LE65 1AH";

        address.City = "Ashby";

        //address.State = 

        address.CountryRegionId = "GBR";

        address.Location = location.RecId;


        dvf = str2Date("08/9/2022", 213);

        dvt = str2Date("08/9/2029", 213);


        address.ValidFrom = DateTimeUtil::newDateTime(dvf,0);

        address.ValidTo = DateTimeUtil::newDateTime(dateMax(),0);

        //partylocation.Party = CustTable.Party;

        addressView.initFromPostalAddress(address);

        addressView.Location = address.Location;

        addressView.State = 'Derbyshire';

        //addressView.LocationName = logisticsLocation.Description;


        addressView.IsPrimary = true;

        addressView.LocationName = location.Description;


        addressView.Party = CustTable.Party;

       // addressview.initFromPostalAddress(address);

        

        paddressView.initFromPartyPostalAddressView(addressView);

        //paddressView.insert();

        postalAddressEntity = LogisticsPostalAddressEntity::construct();

        postalAddressEntity.createPostalAddress(paddressView);

        

        DirParty = DirParty::constructFromPartyRecId(CustTable.Party);


        roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Business).RecId];

        DirParty.createOrUpdatePostalAddress(addressView,roles);



        //

        info(strFmt("Customer %1 Description %2 Address %3",custtable.AccountNum,addressView.LocationName,address.Street));

    }

         info("done");


 } 

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...