Added in additional logic to keep repeated notifications from sending

This commit is contained in:
Infineon\Ouellette 2024-11-18 11:14:11 -07:00
parent 2b6e5fd2ac
commit 91cb72c509

View File

@ -32,6 +32,13 @@ LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : '
Headers = 'Logging DTM' : @FM : 'ToolID' : @FM : 'Notes' : @FM : 'Message'
objLogScrubbers = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$)
LogPath = Environment_Services('GetApplicationRootPath') : '\LogFiles\PM\Notifications'
LogDate = Oconv(Date(), 'D4/')
LogTime = Oconv(Time(), 'MTS')
LogFileName = LogDate[7, 4] : '-' : LogDate[1, 2] : '-' : LogDate[4, 2] : ' PM_Notifications.csv'
Headers = 'Logging DTM' : @FM : 'ToolID' : @FM : 'Message'
objLogNotifications = Logging_Services('NewLog', LogPath, LogFileName, CRLF$, ',', Headers, '', False$, False$)
LoggingDTM = LogDate : ' ' : LogTime ; // Logging DTM
ChangeModes = Database_Services('ReadDataRow', 'APP_INFO', 'QUAL_CHANGE_MODES')
@ -644,18 +651,18 @@ end service
Service SendPMNotifications()
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
Lock hSysLists, ServiceKeyID then
PMStatuses = Pm_Services('GetPMStatuses')
* Recipients = Lsl_Users_Services('GetOnShiftUsersByClass', 'Si Shift Supervisors', 0)
* Recipients := @VM : Lsl_Users_Services('GetOnShiftUsersByClass', 'Lead Operator', 0)
SentFrom = 'OI_ADMIN'
AttachWindow = ''
AttachKey = ''
SendToGroup = ''
errMessage = ''
PMStatuses = Pm_Services('GetPMStatuses')
SentFrom = 'OI_ADMIN'
AttachWindow = ''
AttachKey = ''
SendToGroup = ''
for each PMStatusLine in PMStatuses using @FM
Status = PMStatusLine<1,COL$STATUS>
LastNotification = PMStatusLine<1,COL$NOTIFICAITON>
PMDesc = XLATE('PM_SPEC', PMStatusLine<1,COL$PMSKEY>, PM_SPEC_DESC$, 'X')
PMKey = PMStatusLine<1,COL$CURRPMKEY>
PMRec = Database_Services('ReadDataRow', 'PM', PMKey)
PMSpecKey = PMStatusLine<1, COL$PMSKEY>
PMSRec = Database_Services('ReadDataRow', 'PM_SPEC', PMSpecKey)
@ -667,33 +674,120 @@ Service SendPMNotifications()
Begin Case
Case Status EQ 'EARLY'
IF SendEarlyNotification then
Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey)
Subject = 'PM Task Coming Due'
Message = 'Tool: ': Tool : ' - ' :PMDesc:" is coming due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
PMRec<PM_EARLY_NOTIF_SENT$> = Datetime()
Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
If PMRec<PM_EARLY_NOTIF_SENT$> EQ '' then
PMRec<PM_EARLY_NOTIF_SENT$> = Datetime()
Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
if Error_Services('NoError') then
Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey)
if Error_Services('NoError') then
Subject = 'PM Task Coming Due'
Message = 'Tool: ': Tool : ' - ' :PMDesc:" is coming due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
end else
errMessage = Error_Services('GetMessage')
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'EARLY notification failed - ' : errMessage
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end else
errMessage = Error_Services('GetMessage')
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'EARLY notification failed - ' : errMessage
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end else
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'EARLY notification did not send because it has been marked as being already sent.'
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end
Case Status EQ 'DUE'
If SendDueNotification then
Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey)
Subject = 'PM Task Due'
Message = 'Tool: ': Tool : ' - ' :PMDesc:" is due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
PMRec<PM_DUE_NOTIF_SENT$> = Datetime()
Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
If PMRec<PM_DUE_NOTIF_SENT$> EQ '' then
PMRec<PM_DUE_NOTIF_SENT$> = Datetime()
Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
if Error_Services('NoError') then
Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey)
if Error_Services('NoError') then
Subject = 'PM Task Due'
Message = 'Tool: ': Tool : ' - ' :PMDesc:" is due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
end else
errMessage = Error_Services('GetMessage')
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'DUE notification failed - ' : errMessage
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end else
errMessage = Error_Services('GetMessage')
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'DUE notification failed - ' : errMessage
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end else
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'DUE notification did not send because it has been marked as being already sent.'
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end
Case Status EQ 'LATE'
if SendLateNotification then
Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey)
Subject = 'PM overdue'
Message = 'Tool: ': Tool : ' - ' :PMDesc:" is overdue. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
PMRec<PM_LATE_NOTIF_SENT$> = Datetime()
Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
If PMRec<PM_LATE_NOTIF_SENT$> EQ '' then
PMRec<PM_LATE_NOTIF_SENT$> = Datetime()
Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
if Error_Services('NoError') then
Recipients = PM_Services('GetPMNotificationRecipients', PMSpecKey)
if Error_Services('NoError') then
Subject = 'PM overdue'
Message = 'Tool: ': Tool : ' - ' :PMDesc:" is overdue. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
obj_Notes('Create',Parms)
end else
errMessage = Error_Services('GetMessage')
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'LATE notification failed - ' : errMessage
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end else
errMessage = Error_Services('GetMessage')
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'LATE notification failed - ' : errMessage
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end else
LogData = ''
LogData<1> = LoggingDTM;//Defined at entry of subroutine
LogData<2> = Tool
LogData<3> = PMDesc
LogData<4> = 'LATE notification did not send because it has been marked as being already sent.'
Logging_Services('AppendLog', objLogNotifications, LogData, @RM, @FM, False$)
end
end
End Case
end
@ -703,68 +797,6 @@ Service SendPMNotifications()
end service
* Service SendPMNotifications()
*
* hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
* Lock hSysLists, ServiceKeyID then
*
* PMStatuses = Pm_Services('GetPMStatuses')
* Recipients = Lsl_Users_Services('GetOnShiftUsersByClass', 'Si Shift Supervisors', 0)
* Recipients := @VM : Lsl_Users_Services('GetOnShiftUsersByClass', 'Lead Operator', 0)
* SentFrom = 'OI_ADMIN'
* AttachWindow = ''
* AttachKey = ''
* SendToGroup = ''
* for each PMStatusLine in PMStatuses using @FM
* Status = PMStatusLine<1,COL$STATUS>
* LastNotification = PMStatusLine<1,COL$NOTIFICAITON>
* PMDesc = XLATE('PM_SPEC', PMStatusLine<1,COL$PMSKEY>, PM_SPEC_DESC$, 'X')
* PMKey = PMStatusLine<1,COL$CURRPMKEY>
* PMRec = Database_Services('ReadDataRow', 'PM', PMKey)
* PMSpecKey = PMStatusLine<1, COL$PMSKEY>
* PMSRec = Database_Services('ReadDataRow', 'PM_SPEC', PMSpecKey)
* //SendNotification = PMSRec<PM_SPEC_SEND_NOTIFICATION$>
* SendEarlyNotification = PMSRec<PM_SPEC_SEND_EARLY_NOTIFICATION$>
* SendDueNotification = PMSRec<PM_SPEC_SEND_DUE_NOTIFICATION$>
* SendLateNotification = PMSRec<PM_SPEC_SEND_LATE_NOTIFICATION$>
* If LastNotification EQ '' then
* Begin Case
* Case Status EQ 'EARLY'
* IF SendEarlyNotification then
* Subject = 'PM Task Coming Due'
* Message = PMDesc:" is coming due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
* Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
* obj_Notes('Create',Parms)
* PMRec<PM_EARLY_NOTIF_SENT$> = Datetime()
* Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
* end
* Case Status EQ 'DUE'
* If SendDueNotification then
* Subject = 'PM Task Due'
* Message = PMDesc:" is due. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
* Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
* obj_Notes('Create',Parms)
* PMRec<PM_DUE_NOTIF_SENT$> = Datetime()
* Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
* end
* Case Status EQ 'LATE'
* if SendLateNotification then
* Subject = 'PM overdue'
* Message = PMDesc:" is overdue. Scheduled due by " : OCONV(PMStatusLine<1,COL$DUEBY>, 'DT')
* Parms = Recipients:@RM:SentFrom:@RM:Subject:@RM:Message:@RM:AttachWindow:@RM:AttachKey:@RM:SendToGroup
* obj_Notes('Create',Parms)
* PMRec<PM_LATE_NOTIF_SENT$> = Datetime()
* Database_Services('WriteDataRow', 'PM', PMKey, PMRec, 1, 0, 1)
* end
* End Case
* end
* Next PMStatus
* Unlock hSysLists, ServiceKeyID else Null
* end
*
* end service
Service GetPMStatuses()
SendEarlyCnt = 0
@ -934,3 +966,4 @@ Service CompleteScrubberPM(ScrubberID)
end
end service