Customizing the Creation of Incidents
The application provides events to customize the creation of incidents.
Incidents Header Created from Documents
The following explains how to add (custom) fields in the header of incidents reported from source documents.
The OnBeforeCreateIncidentHeaderFromSource event, triggered by the IDPIMG Create Incident page when reporting an incident from a document, allows, for example, to add and fill in custom fields to the incident header.
local procedure OnBeforeCreateIncidentHeaderFromSource(var TempIncSourceDoc: Record "IDPIMG Inc. Source Doc." temporary; var IncidentHeader: Record "IDPIMG Incident Header")
The event is triggered just before inserting the header of the new incident to be created, and receives as parameter a temporary record from the table "IDPIMG Inc. Source Doc. ", which identifies the source document and the record that corresponds to the header of the incident to be created.
Below is an example of customization using this event, where the user, in addition to the data requested by the app by default when reporting an incident from the source document (Description, Date/Time, Category, Type, etc.), must indicate the City where the incident occurred and, additionally, the Customer No. of the source document must be filled in automatically, in case there is one.
- The desired fields will have to be added both in the IDPIMG Incident Header table and, optionally, in the IDPIMG Inc. Source Doc. table, which is the table on which the incident creation page from source document is based. This is a temporary table where the only fields are those that identify the source document (Document Type, Document No. and “Service Item Line No.” and “Service Item No.”, for the case of two-level service documents). In the example, the field "Incident City " is added.
tableextension 50103 "MYPRE Inc. Source Doc." extends "IDPIMG Inc. Source Doc."
{
fields
{
field(50108; "Incident City"; Text[250])
{
Caption = 'Incident City';
DataClassification = CustomerContent;
}
}
}
tableextension 50102 "MYPRE Incident Header" extends "IDPIMG Incident Header"
{
fields
{
field(50100; "MYPRE Customer No."; Code[20])
{
Caption = 'Customer No.';
TableRelation = Customer."No.";
DataClassification = CustomerContent;
}
field(50108; "Incident City"; Text[250])
{
Caption = 'Incident City';
DataClassification = CustomerContent;
}
}
}
You will have to make a PageExtension of the page shown when creating incidents from source documents, IDPIMG Create Incident, which is based on the "IDPIMG Inc. Source Doc." temporary table, adding the new fields from the "IDPIMG Inc. Source Doc." table, if any.
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 incident creation process. 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 is in Lookup mode).
pageextension 50102 "MYPRE Create Incident" extends "IDPIMG Create Incident"
{
layout
{
addlast("New Incident Details")
{
field("Incident City"; IncidentCity)
{
ApplicationArea = All;
MultiLine = true;
ToolTip = 'Specify the city in which the incident occurred.';
}
}
}
trigger OnClosePage()
begin
Rec."Incident City" := IncidentCity;
end;
var
IncidentCity: Text[250];
}
We must subscribe to the OnBeforeCreateIncidentHeaderFromSource event of the IDPIMG Create Incident page, to pass the value of the new columns added in the incident creation dialog box to the header of the incident being created, or to fill in new fields in the incident header from the source documents. In the example, the "Incident City" field is added, which must be filled in by the user, and the Customer No. field is also filled in, which has also been added to the incident header, from the source document of the incident, i.e. it does not have to be filled in by the user in the Create Incident From Source Document dialog box. An example has been put in the case statement with only one type, though, obviously, you must add all the types from which the client should be filled in. An error could also be thrown if a new field must be filled and it is not before the incident is created.
NoteThe Rec in the IDPIMG Create Incident dialog box has the fields that identify the source document, "Document Type" and "Document No.", as well as the "Service Item Line No." and "Service Item No.", so that values can be retrieved from the source document (by means of a case of all possible incident source types) that pass directly from the source document to the incident header, without the need to add any in the IDPIMG Inc. Source Doc table.
// ***** CUSTOMIZATION TO ADD MORE FIELDS WHEN CREATING INCIDENTS
[EventSubscriber(ObjectType::Page, Page::"IDPIMG Create Incident", 'OnBeforeCreateIncidentHeaderFromSource', '', false, false)]
local procedure OnBeforeCreateIncidentHeaderFromSource(var TempIncSourceDoc: Record "IDPIMG Inc. Source Doc.";
var IncidentHeader: Record "IDPIMG Incident Header")
var
ServiceHeader: Record "Service Header";
IncidentSetup: Record "IDPIMG Incidents Setup";
begin
// Fields that the user must fill in.
if TempIncSourceDoc."Incident City" <> '' then
IncidentHeader.Validate("Incident City", TempIncSourceDoc."Incident City");
case TempIncSourceDoc."Document Type" of
TempIncSourceDoc."Document Type"::"Service Order":
begin
// Fields that come from the Source Document.
if ServiceHeader.Get(ServiceHeader."Document Type"::Order, TempIncSourceDoc."Document No.") then
IncidentHeader.Validate("MYPRE Customer No.", ServiceHeader."Customer No.");
end;
end;
end;
Incident Lines
The lines of an incident, in addition to the fields that identify the source document line (Document Type and No., Document Line No., Document Subline No.), have a series of fields that allow you to quickly identify key concepts without having to navigate to the source document (Product, Customer, Vendor, Salesperson, Shipping Agent). These fields are automatically filled in the OnValidate of the Document Line No. field (or Document Subline No. for service lines), both when lines are inserted from the card of an incident, as well as when they are automatically inserted when reporting incidents from source documents.
Therefore, without the need for any additional event, if you wish to add more fields in the incident lines from the source document lines, simply subscribe to the OnAfterValidate of the Document Line No. field (or Document Subline No. for service lines).
Below is an example of customization using this event where, in addition to the data that is automatically filled in when a line from the source document is inserted, the quantity must be filled in as well.
tableextension 50100 "MYPRE Incident Line" extends "IDPIMG Incident Line"
{
fields
{
modify("Document Line No.")
{
trigger OnAfterValidate()
var
ServiceLine: Record "Service Line";
begin
// ***** CUSTOMIZATION TO ADD MORE FIELDS WHEN CREATING INCIDENT LINES *****
case Rec."Document Type" of
Rec."Document Type"::"Service Invoice":
if ServiceLine.Get(ServiceLine."Document Type"::Invoice, Rec."Document No.", Rec."Document Line No.") then
Rec."MYPRE Quantity" := ServiceLine.Quantity;
end;
end;
}
field(50100; "MYPRE Quantity"; Decimal)
{
Caption = 'Quantity';
DataClassification = CustomerContent;
}
}
}