ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

API Pages AfterInsert Logic in Triggers OnQueryClosePage/OnClosePage

Open MichaelSchauer98 opened this issue 5 years ago • 3 comments

Hi,

I need to add some AfterInsert functionality to a Custom API Page where the record of the API is already inserted. To be more specific, if a Customer is inserted via this API Page a new Contact Business Relation shall be created if a linked Contact has been found. After some testing I have discoverd that the OnQueryClosePage/OnClosePage is run when the Customer is already inserted and that this newly created Customer can be Validated into the "No." field of the Contact Business Relation. My question is: Is the OnCloseQueryPage Trigger on API Pages intended to behave like that and can be used to handle e.g. AfterInsert logic?

Kind Regards

MichaelSchauer98 avatar Sep 10 '21 10:09 MichaelSchauer98

@nikolakukrika - can you help?

AlexanderYakunin avatar Sep 16 '21 12:09 AlexanderYakunin

Hi, OnQueryClosePage and OnClosePage triggers are not intended to handle web service clients. They are designed to be invoked only when page is hosted in a modal popup window (MPO), therefore a UI client. Instead you can use the OnInsertRecord trigger and insert the record yourself, that way you'd be sure that the record is inserted and have your additional logic afterwards. Another option could be to subscribe to OnAfterInsertRecord event on the source table, and check the client type.

[EventSubscriber(ObjectType::Table, Database::Customer, 'OnAfterInsertEvent', '', false, false)]
local procedure HandleOnAfterCustomerInsert(var Rec: Record Customer)
var
        ClientTypeManagement: Codeunit "Client Type Management";
begin
        if ClientTypeManagement.GetCurrentClientType() = ClientType::ODataV4 then
                    //do stuff
end;

onbuyuka avatar Sep 20 '21 11:09 onbuyuka

Thank you @onbuyuka, issue can be closed

MichaelSchauer98 avatar Nov 10 '21 07:11 MichaelSchauer98