Hi,
In this post will showcase the code where we can use SysDa framework with the help of class SysDaValidTimeStateDateTimeRange to deal with data and time in X++ queries.
Note: CG_SysDaQueryTime is a runnable class.
class CG_SysDaQueryTime{ /// <summary> /// SysDaQueryObject - Implementing time function. /// </summary> /// <param name = "_args">The specified arguments.</param> public static void main(Args _args) { /* Effective X++ Statement(s)/code - public static HcmEmployment find(HcmWorkerRecId _worker, CompanyInfoRecId _legalEntity, Utcdatetime _validFrom = DateTimeUtil::minValue(), Utcdatetime _validTo = DateTimeUtil::maxValue(), boolean _forUpdate = false) { HcmEmployment hcmEmployment; utcdatetime validFrom, validTo; validFrom = DateTimeUtil::minValue(); validTo = DateTimeUtil::maxValue(); if (_worker && _legalEntity) { if (_forUpdate) { hcmEmployment.selectForUpdate(_forUpdate ); } select firstonly ValidTimeState(validFrom, validTo) hcmEmployment where hcmEmployment.Worker == _worker && hcmEmployment.LegalEntity = _legalEntity; } return hcmEmployment; } */ HcmPersonnelNumberId personnelNumber = "0001"; DirPersonName dirPersonName; CompanyInfo companyInfo; HcmEmployment hcmEmployment; companyInfo = CompanyInfo::find(); hcmEmployment = CG_SysDaQueryTime::find(HcmWorker::findByPersonnelNumber(personnelNumber).RecId, companyInfo.RecId, DateTimeUtil::utcNow(), DateTimeUtil::utcNow()); #File if (hcmEmployment.RecId != 0) { dirPersonName = DirPersonName::find(DirPerson::find(HcmWorker::find(hcmEmployment.Worker).Person).RecId); info(strFmt("Worker %1 actively exists in legal entity %2", dirPersonName.FirstName, companyInfo.DataArea)); } } public static HcmEmployment find(HcmWorkerRecId _worker, CompanyInfoRecId _legalEntity, Utcdatetime _validFrom = DateTimeUtil::minValue(), Utcdatetime _validTo = DateTimeUtil::maxValue(), boolean _forUpdate = false) { HcmEmployment hcmEmployment; SysDaQueryObject sysDaQuery = new SysDaQueryObject(hcmEmployment); if (_worker && _legalEntity) { if (_forUpdate) { // Select for update sysDaQuery.forUpdateHint = true; } // Imposes optimistic lock sysDaQuery.optimisticLockHint = true; // Select firstonly sysDaQuery.firstOnlyHint = true; sysDaQuery.whereClause(new SysDaEqualsExpression (new SysDaFieldExpression(HcmEmployment, fieldStr(HcmEmployment, Worker)), new SysDaValueExpression(_worker))); SysDaFindObject findObject = new SysDaFindObject(sysDaQuery); SysDaValidTimeStateDateTimeRange sysDaValidDateTime = new SysDaValidTimeStateDateTimeRange(_validFrom, _validTo); findObject.validTimeState(sysDaValidDateTime); new SysDaFindStatement().execute(findObject); } return hcmEmployment; } }Result: OutputRegards,
Chaitanya Golla

Like
Report
*This post is locked for comments