Skip to main content

Posts

Showing posts from October, 2014

validateWrite() in Dynamics AX 2012

public boolean validateWrite() {     boolean ret=true;     HCMJob                  _HCMJob;     HcmPositionDetail       _HcmPositionDetail;     int                     _diff;     ;         select * from _HCMJob where _HCMJob.RecId == HRMRecruitingTable.Job;     select   count(recId) from _HcmPositionDetail   where _HcmPositionDetail.Job == HRMRecruitingTable.Job;     _diff = _HCMJob.MaximumPositions-_HcmPositionDetail.RecId;        if (HRMRecruitingTable.qty>_diff)     {         ret = false;     }   if (ret)     {         ret = super();     }     else     {     if (HRMRecruitingTable.qty>_diff)        {             info("You cannot Add Any Opening");        }        else        {             info("You Cannot Add more than " + int2str( _diff )+ " Opening");        }     }     return ret; }

Add Month in Date on the behalf of other Date Field

public boolean modified() {     boolean ret;     utcDateTime _CloseDate;     utcDateTime _OpenDate;     Date _FinalDate;     ret = super();             _OpenDate = DateTimeUtil::newDateTime(HRMRecruitingTable.startDate, 0, DateTimeUtil::getCompanyTimeZone());     _CloseDate = DateTimeUtil::addMonths(_OpenDate, 3);     _FinalDate = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(_CloseDate, DateTimeUtil::getUserPreferredTimeZone()));       HRMRecruitingTable.endDate = _FinalDate;             return ret; }

Container and unbounded string (text) fields are not allowed in a WHERE expression in AX

Reason : Axapta does not allow you to use an unbounded string in a where clause Solution : You must use a ‘bounded’ string. To do this you must declare your string with a numerical limiter e.g. str 50. Example: PurchTable getFirstByCustomerPOId(str 50 customerPOId) { PurchTable purchTable; ; purchTable.selectForUpdate(true); select firstonly purchTable where purchTable.My_CustomerPurchaseOrderId == customerPOId; return purchTable; }