[Event Request] codeunit 2000000002 "Global Triggers", codeunit 49 GlobalTriggerManagement
Dear ALAppExtensions team, please add Currcompany parameters to this event:
codeunit 2000000002 "Global Triggers"
[BusinessEvent(false)]
procedure GetDatabaseTableTriggerSetup(TableId: Integer; var OnDatabaseInsert: Boolean; var OnDatabaseModify: Boolean; var OnDatabaseDelete: Boolean; var OnDatabaseRename: Boolean)
begin
end;
codeunit 49 GlobalTriggerManagement
[EventSubscriber(ObjectType::Codeunit, 2000000002, 'GetDatabaseTableTriggerSetup', '', false, false)]
local procedure GetDatabaseTableTriggerSetup(TableId: Integer; var OnDatabaseInsert: Boolean; var OnDatabaseModify: Boolean; var OnDatabaseDelete: Boolean; var OnDatabaseRename: Boolean)
var
IntegrationManagement: Codeunit "Integration Management";
ChangeLogMgt: Codeunit "Change Log Management";
begin
ChangeLogMgt.GetDatabaseTableTriggerSetup(TableId, OnDatabaseInsert, OnDatabaseModify, OnDatabaseDelete, OnDatabaseRename);
IntegrationManagement.GetDatabaseTableTriggerSetup(TableId, OnDatabaseInsert, OnDatabaseModify, OnDatabaseDelete, OnDatabaseRename);
OnAfterGetDatabaseTableTriggerSetup(TableId, OnDatabaseInsert, OnDatabaseModify, OnDatabaseDelete, OnDatabaseRename);
end;
[IntegrationEvent(false, false)]
local procedure OnAfterGetDatabaseTableTriggerSetup(TableId: Integer; var OnDatabaseInsert: Boolean; var OnDatabaseModify: Boolean; var OnDatabaseDelete: Boolean; var OnDatabaseRename: Boolean)
begin
end;
The parameters "TableID" it is not enough to recover the company on which it is operating. for example: In the trigger recall phase (Modify, Delete, Rename, Insert) through Webservice exposed by a single endpoint, on a master company ...... if the trigger must be performed on a other company other than the one on which the webservice, the operation takes place on the COMPANYNAME (of the webservice).
Thanks
Requested a fix to the platform.
The user always works in the scope of a company either in the web client or with API / Odata calls
Correct. CompanyName will always return the current company, thus adding any additional information is not necessary
I wrote the reason in my post: it is necessary if the operation must be carried out on another company. example: unique endpoint on MASTER company
https://api.businesscentral.dynamics.com/v2.0/tenantId/Production/WS/Master/Codeunit/WSBcentral
call method: "ModifyGLAccountName"(ApplyToCompany,AccounNo, NewAccountName):
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope> soapenv:Header/ soapenv:Body wsb:ModifyGLAccountName wsb:ApplyToCompanySLAVE</wsb:ApplyToCompany> wsb:upgradeGLAccounts x55:Account x55:AccounNo10202010001</x55:AccounNo> x55:NewAccountNametest</x55:NewAccountName> </x55:Account> </wsb:upgradeGLAccounts> </wsb:ModifyGLAccountName> </soapenv:Body> </soapenv:Envelope>
In the method procedure I have: if ApplyToCompany<>COMPANYNAME then T15.ChangeCompany (ApplyToCompany);
IF T15.GET(AccounNo) THEN BEGIN T15.Name: = NewAccountName; T15.Modify; END;
the triggers run always on COMPANYNAME of exposed webservice , in this case is MASTER.
You should be aware that ChangeCompany only changes the company for the current record instance. Hence it is strongly recommended not to make changes to records where you have called ChangeCompany, as the CurrentCompany is unchanged for all event subscribers in the call chain (new record variables will be created in CurrentCompany etc.).
What you should do instead is to create a session in the target company and make the changes there - and only use ChangeCompany for Reading across companies. Since reading does not invoke the global triggers, then we are not going to modify the signature of the event.
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordref/recordref-changecompany-method
does state: Even if you run the CHANGECOMPANY method, triggers still run in the current company, not in the company that you specified in the CHANGECOMPANY method.
I know what you're talking about. in the attached file this you can see my procedure ExampleCode.zip
For Master/slave app: Codeunit 80100 : single instance for my code on trigger Codeunit 80101: for link to codeunit 49 events.
For APP that expose WebService: Codeunit 55002: exposed web service on MASTER company, with method ModifyGlAccounts XmlPort 55009 : to import data from WS, with companyname when data will have to be sent; Codeunit 55012 : singleinstance codeunit to set temporary info
I would like it to be inserted in the GetDatabaseTableTriggerSetup event because in this way, working with single instances, I would exclude the execution of the code in the events to which I have subscribed my code. The indication of only the TableId is limiting and incomplete.
We do not plan to add this to the trigger in the near future. Although I understand the scenario, then it conveys the wrong message about calling Modify etc. in other companies - that is to be avoided. A much better approach is to gather the information and then run a task in the other company (using CreateTask, CreateSession or similar). The database can be used to pass the information over (reading it from the other company, storing the 'receipt in the other company', then read receipt from original company)
We would rather look at exposing tasks as a synchronous operation inside the same transaction - but that is also not currently planned.