Select Line Event
Business Portals can trigger an event when a line is selected on the frontend. This selection is sent to Business Central, where it can be processed by a custom codeunit to perform actions such as recalculating values or updating related data.
This section provides an example of how to implement a custom codeunit that is triggered when a line is selected by the user.
Code Example
In this example, we will use the Sales Order Line table in a scenario where selecting a line triggers an event that can, for instance, update related fields or perform validations.
The line selection sends data to Business Central, where it is processed in a Business Central codeunit.
AL
'SELECTLINE':
begin
LocalEventXmlElement := XmlElement.Create('EVENT');
LocalRootXmlElement.Add(LocalEventXmlElement);
LocalRootXmlElement.SetAttribute('EVENTTYPE', ParamRecordSIMDPSOL."Sub Function Event");
LocalRootXmlElement.SetAttribute('EVENTVALUE', LocalEventValueText);
LocalRootXmlElement.SetAttribute('EVENTMESSAGE', 'All lines with the same quantity will be selected.');
LocalRootXmlElement.SetAttribute('EVENTMESSAGETYPE', 'default');
LocalRootXmlElement.SetAttribute('EVENTMESSAGEMOBILE', 'Since this is a multiple-select field, please enter a value.');
LocalRootXmlElement.SetAttribute('EVENTMESSAGEMOBILETYPE', 'default');
if Evaluate(LocalRecordId, LocalEventValueText, 9) then
if LocalRecordRef.Get(LocalRecordId) then begin
LocalRecordRef.SetTable(LocalRecordSalesLine);
Local2RecordSalesLine.SetRange("Document Type", LocalRecordSalesLine."Document Type");
Local2RecordSalesLine.SetRange("Document No.", LocalRecordSalesLine."Document No.");
Local2RecordSalesLine.SetRange(Quantity, LocalRecordSalesLine.Quantity);
if Local2RecordSalesLine.FindSet() then
repeat
LocalInfoXmlElement := XmlElement.Create('INFO');
LocalEventXmlElement.Add(LocalInfoXmlElement);
LocalInfoXmlElement.SetAttribute('VALUE', Format(Local2RecordSalesLine.RecordId, 0, 9));
until Local2RecordSalesLine.Next() = 0;
end;
end;