Quantcast
Channel: Microsoft Dynamics AX
Viewing all articles
Browse latest Browse all 101540

Forum Post: RE: Faulty missing timesheet notification email in AX 2012?

$
0
0
Hi Andre, One emp. has her employment start date: 12/03/2015, but she has worker periods since 09/28/2015. As your thinking, table hcmemployment is used. Below is the content of run in class : /// /// Contains the code that does the actual job of the class. /// public void run() { HcmWorker hcmWorker, hcmManager; HcmPositionRecId hcmPositionId; HcmWorkerRecId hcmManagerId; HcmEmployment hcmEmployment; ProjParameters projParameters; ProjPeriodLine projPeriodLine; ProjWorkerSetup projWorkerSetup; TSTimesheetTable tsTimesheetTable; str userName, managerName; SysEmailId sysEmailId; SysUserInfo sysUserInfo; Map mappings = new Map(Types::String,Types::String); int emailsSent =0, missingEmailIds =0; // Method to convert the DateTime to Date applying the timezone offset date convertToDate(utcDateTime _dateTime) { return DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(_dateTime, DateTimeUtil::getUserPreferredTimeZone())); } this.initQuery(); // Get the email template Id from the projParameters table select firstOnly MissingTimesheetsEmailId from projParameters; sysEmailId = projParameters.MissingTimesheetsEmailId; if (!sysEmailId) { // If the email template Id is not found, throw an error. throw error("@SYS4003506"); } startLengthyOperation(); ttsbegin; while (queryRun.next()) { projWorkerSetup = queryRun.get(tableNum(ProjWorkerSetup)); projPeriodLine = queryRun.get(tableNum(ProjPeriodLine)); tsTimesheetTable = queryRun.get(tableNum(TSTimesheetTable)); hcmEmployment = queryRun.get(tableNum(HcmEmployment)); // As we have relaxed the ranges by 2 days on both sides in the query earlier, we perform a strict check here. if(((convertToDate(hcmEmployment.ValidTo) = periodFromDate)) || ((convertToDate(hcmEmployment.ValidFrom) = periodFromDate)) || ((convertToDate(hcmEmployment.ValidFrom) = periodToDate))) { // Find the worker from HcmWorker table to get the data hcmWorker = HcmWorker::find(projWorkerSetup.Worker); hcmPositionId = HcmWorker::getPrimaryPosition(projWorkerSetup.Worker); hcmManagerId = HcmPosition::getReportsToWorker(hcmPositionId); hcmManager = HcmWorker::find(hcmManagerId); managerName = hcmManager.name(); // If the timesheet's approval status is Create(Draft), All(Missing) or Returned then send email if (hcmWorker.email() && (tsTimesheetTable.ApprovalStatus == TSAppStatus::All || tsTimesheetTable.ApprovalStatus == TSAppStatus::Create || tsTimesheetTable.ApprovalStatus == TSAppStatus::Returned) ) { sysUserInfo = sysUserInfo::find(curuserid()); userName = sysUserInfo.Email; mappings.insert('name', hcmWorker.name()); mappings.insert('telephone', hcmWorker.phone()); mappings.insert('hours',strfmt("%1", tsTimesheetTable.totalHours())); mappings.insert('periodCode', projWorkerSetup.PeriodId); mappings.insert('timesheetNumber', tsTimesheetTable.TimesheetNbr); // If 'All' is the timesheet status, replace it with 'No timesheet' if(tsTimesheetTable.ApprovalStatus == TSAppStatus::All) { mappings.insert('status', "@SYS4003505"); } else { mappings.insert('status', enum2str(tsTimesheetTable.ApprovalStatus)); } mappings.insert('periodTo', date2StrUsr(projPeriodLine.PeriodTo, DateFlags::FormatAll)); mappings.insert('periodFrom',date2StrUsr(projPeriodLine.PeriodFrom, DateFlags::FormatAll)); mappings.insert('manager', managerName); // Send email SysEmailTable::sendMail(sysEmailId, SysEmailTable::find(sysEmailId).DefaultLanguage, hcmWorker.email(), mappings, '', '', true, userName, true); emailsSent++; } else if (!hcmWorker.email()) { // If the worker does not have the email configured, increment the missing email Ids counter. missingEmailIds++; } } } info(strFmt("@SYS4003503", emailsSent, missingEmailIds)); ttscommit; endLengthyOperation(); } Thanks Thai

Viewing all articles
Browse latest Browse all 101540


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>