Sunday 30 March 2014

Refreshing form's datasource without affecting cursor position / How to retain cursor position? in AX

WE can do in two ways
1.Just calling the Research method by passing true boolean value
 MyTable_ds.research(true); // boolean value retain the cursor position
 ------------
2.you can use method setPosition() and getPosotion()
 {
 int position;
 ;
 position= MyTable_ds.getPosition();
 MyTable_ds.research();
 MyTable_ds.setPosition(position);
 }

Thursday 27 March 2014

How to get the first and the last day of a month

The first day of a month

static void FirstOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate FirstOfMth;
   ;

   FirstOfMth=mkdate(1,mthofyr(TransDate),year(TransDate));

   info(date2str(FirstOfMth,123,2,2,2,2,4));
}

--------------Or--------------------------
static void FirstOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate FirstOfMth;
   ;
   FirstOfMth=DateStartMth(TransDate);

   info(date2str(FirstOfMth,123,2,2,2,2,4));
}

The first day of a month

static void LastOfMonth(Args _args)
{
   TransDate TransDate=today();
   TransDate LastOfMth;
   ;

   LastOfMth=endmth(TransDate);

   info(date2str(LastOfMth,123,2,2,2,2,4));
}

--------------Or--------------------------

static void LastDateofMonth(Args _args)
{
    yr                            y = 2012;
    int                           m = 02;
    TransDate           endDate;
    int                          NoOfDays;
    ;
    endDate   = Global::dateEndMth(mkdate(01,m,y));
    NoOfDays  = dayOfMth(endDate);
    info(strfmt("%1",NoOfDays));
}

Date functions in AX 2012

static void date_Functions(Args _args)
{
    Transdate    d;
    str s;
    ;

    d = today();
  //  s =date2str(d,1,4,1,4,1,4,214);

    info(strfmt("Date - %1",d));

    //Gets the month for the given date...
    info(strfmt("Month - %1",mthofYr(d)));

    //Gets the month name from the given date...
    info(strfmt("Month Name - %1",mthname(mthofYr(d))));

    //Gets the day for the given date...
    info(strfmt("Day - %1",dayOfMth(d)));

    //Gets the day name from the given date...
    info(strfmt("Day Name - %1",dayname(dayOfwk(d))));
   // info(strfmt("Day Name - %1",dayName(s)));
    //Gets the year for the given date...
    info(strfmt("Year - %1",year(d)));

    //Gets the current weekday number from the date...
    info(strfmt("Weekday number - %1",dayOfwk(d)));

    //Gets the day of the year from the given date...
    info(strfmt("Day of year - %1",dayOfyr(d)));

    //Gets the week of the year from the given date...
    info(strfmt("Week of the year - %1",wkofyr(d)));
}


Code for Deleting address information in ax 2012

static void Delete_vendTable(Args _args)
{
DirPartyPostalAddressView DirPartyPostalAddressView;
VendTable vendTable;
CustTable  CustTable;
LogisticsLocation location;
;

ttsBegin;

while select CustTable
{
info(strFmt("Customer %1",CustTable.AccountNum));

while select DirPartyPostalAddressView where DirPartyPostalAddressView.Party == CustTable.Party
                                          && !DirPartyPostalAddressView.IsPrimary
{
location = LogisticsLocation::find(DirPartyPostalAddressView.Location,true);

if(location.validateDelete())
location.delete();
}
}

ttsCommit;
}