Customize the Reopening of Incidents
The application provides events to customize the reopening of incidents.
The following explains how to fill in (customized) fields in the incident reopening process, both in the automatically generated reopening entry and, optionally, in the incident header itself.
On the page shown to the user when reopening an incident, IDPIMG Reopen Incident, the OnBeforeInsertIncidentEntryWhenReopenIncident event is published so that we can subscribe to it and add more custom fields in the entry to reopen the incident.
local procedure OnBeforeInsertIncidentEntryWhenReopenIncident(var TempReopeningIncident: Record "IDPIMG Incident Header" temporary; var IncidentEntry: Record "IDPIMG Incident Entry")
The event is triggered just before inserting the automatically generated incident reopening entry, and receives as parameters a temporary record from the IDPIMG Incident Header table (the incident to be reopened), and the record corresponding to the reopening entry.
In the IDPIMG Incident Management codeunit, an event, OnBeforeModifyIncidentHeaderWhenReopenIncident, is triggered in the ReopenIncident function, which is called when an incident is reopened, after the reopen entry is created, to change the status of the incident to Open, so that we can subscribe to it and modify more custom fields in the incident header.
local procedure OnBeforeModifyIncidentHeaderWhenReopenIncident(var TempReopeningIncident: Record "IDPIMG Incident Header" temporary; var IncidentHeader: Record "IDPIMG Incident Header")
The event is triggered just before the incident header is modified after the status change and receives as parameters a temporary record from the "IDPIMG Incident Header table (the incident being reopened), and the incident header itself with the status already as Open.
Below is an example of customization using these events, where the user, in addition to the data requested by the app by default when reopening an incident (reason for reopening, description, etc.), must indicate the date and time at which the actual reopening of the incident occurred, as well as a new check in the incident header (Reopened), which must be marked automatically.
The desired fields are added both in the IDPIMG Incident Entry table and, optionally, in the IDPIMG Incident Header table, on which the page for reopening incidents (IDPIMG Reopen Incident) is based.
TipIt is recommended that, if fields in the IDPIMG Incident Entry and IDPIMG Incident Header tables are duplicated, they be as non-editable in the IDPIMG Incident Header table to be consistent with the app's reopening process, which records reopening information in the incident entries. They can be added to the incident header for convenience for data exploitation and can be added as normal fields or as FlowField fields but, in no case editable since, when an incident is reopened, it is editable again but, the reopening entry is not and the information in one and the other place should not be incoherent.
tableextension 50104 "MYPRE Incident Entry" extends "IDPIMG Incident Entry"
{
fields
{
field(50102; "Reopening Date Time"; DateTime)
{
Caption = 'Date Time of the reopening';
DataClassification = CustomerContent;
}
}
}
tableextension 50102 "MYPRE Incident Header" extends "IDPIMG Incident Header"
{
fields
{
field(50106; "Reopening Code"; Code[10])
{
Caption = 'Reopening Reason Code';
TableRelation = "IDPIMG Incident Reopen Reason".Code;
Editable = false;
DataClassification = CustomerContent;
}
field(50107; Reopened; Boolean)
{
Caption = 'Reopened';
FieldClass = FlowField;
CalcFormula = exist("IDPIMG Incident Entry" where("Incident No." = field("No."),
Action = const(Reopen)));
}
}
}
The page shown when reopening incidents (IDPIMG Reopen Incident) is extended by adding the new information to be filled in. The new fields, even if they were only to be filled in the incident movement table, must also be added in the incident header table, as this is the table on which the incident reopen page is based.
ImportantThey must be added as variables, not as fields, so that they can be editable, since the page is shown in Lookup mode so that the user can cancel the process of reopening the incident. Therefore, in this PageExtension, in the trigger OnClosePage the value of the variables will have to be passed to the corresponding fields of Rec so that, in the following point we can use them (it cannot be done in the Validate of each column because it causes an error due to pages not being able to be updated when opened in Lookup mode).
pageextension 50107 "MYPRE Reopen Incident" extends "IDPIMG Reopen Incident"
{
layout
{
addbefore("Reason Code")
{
group("MYPRE Reopening DateTime")
{
Caption = 'Reopening Date Time';
field(ReopeningDate; ReopeningDate)
{
ApplicationArea = All;
Caption = 'Reopening Date';
ToolTip = 'The real date when the incident was reopened.';
}
field(ReopeningTime; ReopeningTime)
{
ApplicationArea = All;
Caption = 'Reopening Time';
ToolTip = 'The real time when the incident was reopened.';
}
}
}
}
trigger OnOpenPage()
begin
ReopeningDate := Today();
ReopeningTime := Time();
end;
trigger OnClosePage()
begin
Rec."Reopening Date Time" := CreateDateTime(ReopeningDate, ReopeningTime);
end;
var
ReopeningDate: Date;
ReopeningTime: Time;
}
We must subscribe to two events:
OnBeforeInsertIncidentEntryWhenReopenIncident on the IDPIMG Reopen Incident page, to pass the value of new fields added on the incident reopening dialog box to the incident reopening entry that is automatically created. An error could also be thrown if any new field should be filled and is not filled before the incident is reopened.
NoteThe Rec on the IDPIMG Reopen Incident dialog box corresponds to the incident being reopened (temporary copy).
[EventSubscriber(ObjectType::Page, Page::"IDPIMG Reopen Incident", 'OnBeforeInsertIncidentEntryWhenReopenIncident', '', false, false)]
local procedure OnBeforeInsertIncidentEntryWhenReopenIncident(var TempReopeningIncident: Record "IDPIMG Incident Header"; var IncidentEntry: Record "IDPIMG Incident Entry")
begin
IncidentEntry.Validate("Reopening Date Time", TempReopeningIncident."Reopening Date Time");
end;
OnBeforeModifyIncidentHeaderWhenReopenIncident of the IDPIMG Incident Management codeunit, to transfer the value of the new fields added in the reopening dialog box of an incident to the header of the incident being reopened, in case you want to add fields to this header to facilitate the exploitation of the reopening information, even if it is redundant because it is actually stored in the reopening entry.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"IDPIMG Incident Management", 'OnBeforeModifyIncidentHeaderWhenReopenIncident', '', false, false)]
local procedure OnBeforeModifyIncidentHeaderWhenReopenIncident(var TempReopeningIncident: Record "IDPIMG Incident Header"; var IncidentHeader: Record "IDPIMG Incident Header")
begin
IncidentHeader.Validate("Reopening Date Time", TempReopeningIncident."Reopening Date Time");
end;