Ticketstatus Evenement
Het ticketingsysteem van Business Portals kan een evenement triggeren wanneer de ticketstatus op de frontend wordt gewijzigd. Deze statuswijziging wordt naar Business Central gestuurd, waar het kan worden verwerkt door een aangepaste codeunit om acties uit te voeren, zoals het loggen van de interactie of het berekenen hoe lang de ticket in de vorige status heeft gezeten.
Deze sectie biedt een voorbeeld van hoe je een aangepaste codeunit kunt implementeren die wordt getriggerd wanneer de ticketstatus door de gebruiker wordt gewijzigd.
Code Voorbeeld
In dit voorbeeld zullen we de Ticket-tabel gebruiken in een scenario waarin het wijzigen van de ticketstatus een evenement triggert dat bijvoorbeeld de interactiegeschiedenis kan loggen en/of kan berekenen hoe lang de ticket in de vorige status heeft gezeten.
Het wijzigen van de ticketstatus stuurt gegevens naar Business Central, waar het wordt verwerkt in een Business Central codeunit.
// Log Web Interactie parameter
'LogWebInteraction':
begin
EnsureInteractionTemplateExists();
CreateInteractionLog(Rec, LocalRecordSIMDPSTicketStatus);
end;
// Log Overgangstijd parameter
'LogTransitionTime':
CalculateTransitionTime(Rec);
// Log zowel Web Interactie als Overgangstijd parameter
'LogWebAndTransitionTime':
begin
EnsureInteractionTemplateExists();
CreateInteractionLog(Rec, LocalRecordSIMDPSTicketStatus);
CalculateTransitionTime(Rec);
end;
// Deze Procedure zorgt ervoor dat de interactiegroep bestaat in de Interactie Log Entries, als deze niet bestaat, dan zullen we deze aanmaken
local procedure EnsureInteractionTemplateExists()
var
LocalRecordInteractionTemplate: Record "Interaction Template";
LocalRecordInteractionGroup: Record "Interaction Group";
begin
// Veiligheidscontrole: Zorg ervoor dat de Interactie Groep bestaat om validatiefouten te voorkomen
if not LocalRecordInteractionGroup.Get('TICKET') then begin
LocalRecordInteractionGroup.Init();
LocalRecordInteractionGroup.Code := 'TICKET';
LocalRecordInteractionGroup.Description := 'Ticket Operaties';
LocalRecordInteractionGroup.Insert();
end;
// Maak de Interactie Template aan als deze ontbreekt
if not LocalRecordInteractionTemplate.Get('TKT_STATUS') then begin
LocalRecordInteractionTemplate.Init();
LocalRecordInteractionTemplate.Code := 'TKT_STATUS';
LocalRecordInteractionTemplate."Interaction Group Code" := 'TICKET';
LocalRecordInteractionTemplate.Description := 'Wijziging Ticketstatus';
// Stel Standaard Correspondentie Type in op leeg (Spatie) met behulp van de Enum/Optie referentie
LocalRecordInteractionTemplate."Correspondence Type (Default)" := LocalRecordInteractionTemplate."Correspondence Type (Default)"::" ";
LocalRecordInteractionTemplate.Insert();
end;
end;
// Deze Procedure creëert het interactielog in Interactie Log Entries
local procedure CreateInteractionLog(var ParamRecordSIMDPSTicket: Record "SIM_DPS Ticket"; ParamRecordSIMDPSTicketStatus: Record "SIM_DPS Ticket Status")
var
LocalRecordInteractionLogEntry: Record "Interaction Log Entry";
LocalRecordSIMDPSWUBusinessMapping: Record "SIM_DPS WU Business Mapping";
LocalRecordContact: Record Contact;
LocalContactFoundBoolean: Boolean;
LocalStatusChangeLabelMsg: Label 'Ticket %1 gewijzigd naar %2 (%3)', Comment = '%1 = Ticketnummer, %2 = Ticketstatus, %3 = Ticketcategorie';
begin
// Beveilig het volgende Entry No. voor het Interactie Log
LocalRecordInteractionLogEntry.LockTable();
if LocalRecordInteractionLogEntry.FindLast() then
LocalRecordInteractionLogEntry."Entry No." += 1
else
LocalRecordInteractionLogEntry."Entry No." := 1;
// Initialiseer standaard auditvelden
LocalRecordInteractionLogEntry.Init();
LocalRecordInteractionLogEntry.Date := Today();
LocalRecordInteractionLogEntry."Time of Interaction" := Time();
LocalRecordInteractionLogEntry."User ID" := CopyStr(UserId(), 1, MaxStrLen(LocalRecordInteractionLogEntry."User ID"));
LocalRecordInteractionLogEntry.Description :=
CopyStr(StrSubstNo(LocalStatusChangeLabelMsg, ParamRecordSIMDPSTicket."No.", ParamRecordSIMDPSTicketStatus.Code, ParamRecordSIMDPSTicketStatus.Category), 1, MaxStrLen(LocalRecordInteractionLogEntry.Description));
// Wijs Templatecodes toe
LocalRecordInteractionLogEntry."Interaction Template Code" := 'TKT_STATUS';
LocalRecordInteractionLogEntry."Interaction Group Code" := 'TICKET';
// -------------------------------------------------------------------------
// CONTACT MAPPING LOGICA
// -------------------------------------------------------------------------
LocalContactFoundBoolean := false;
// Controleer de Web Gebruiker Business Mapping
LocalRecordSIMDPSWUBusinessMapping.Reset();
LocalRecordSIMDPSWUBusinessMapping.SetRange(Username, ParamRecordSIMDPSTicket.Author);
LocalRecordSIMDPSWUBusinessMapping.SetRange(Company, CompanyName());
LocalRecordSIMDPSWUBusinessMapping.SetRange("DPS Business Mapping Code", 'CONTACT');
if LocalRecordSIMDPSWUBusinessMapping.FindFirst() then begin
LocalRecordInteractionLogEntry."Contact No." := LocalRecordSIMDPSWUBusinessMapping."No.";
LocalContactFoundBoolean := true;
end;
// Terugval voor Interne BC Gebruikers
if not LocalContactFoundBoolean then begin
LocalRecordContact.Reset();
LocalRecordContact.SetRange(Type, LocalRecordContact.Type::Company);
LocalRecordContact.SetRange("Company Name", CompanyName());
// Als er een generieke bedrijfscontact bestaat voor het huidige BC Bedrijf, koppel deze
if LocalRecordContact.FindFirst() then
LocalRecordInteractionLogEntry."Contact No." := LocalRecordContact."No.";
end;
// Commit naar het Interactie Log
LocalRecordInteractionLogEntry.Insert(true);
end;
// Deze Procedure berekent de overgangstijd vanaf het moment dat de status voor het laatst is gewijzigd
local procedure CalculateTransitionTime(var ParamRecordSIMDPSTicket: Record "SIM_DPS Ticket")
begin
if ParamRecordSIMDPSTicket."Status Last Changed At" <> 0DT then
ParamRecordSIMDPSTicket."Transition Duration" := CurrentDateTime() - ParamRecordSIMDPSTicket."Status Last Changed At"
else
if ParamRecordSIMDPSTicket.Created <> 0DT then
ParamRecordSIMDPSTicket."Transition Duration" := CurrentDateTime() - ParamRecordSIMDPSTicket.Created;
end;