Overview
When making a call to the Recalculate Method from the API [Recalculate Method Link], particularly when in an Event Handler, it will likely throw Authentication Errors similar to those below. These can be ignored.
<MetadataEditor>, -, Script execution failed. ((AfterCheckInChangesFinalize::<Handler Name>)) (0x800408BB) ... VaultScriptSessionTemplates.cpp, 340, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) VaultScriptSessionTemplates.cpp, 523, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) CoActiveScriptSite.cpp, 897, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) CoActiveScriptSite.cpp, 739, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) AfterCheckInChangesFinalize::RecalculateCadPackName, 7, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) MNullPropagatingDispatchImpl.h, 126, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) MNullPropagatingDispatchImpl.h, 173, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) CoVaultPropertyDefOperations.cpp, 642, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) ServerVaultPropertyDefOperationsHelper.cpp, 446, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) Helper.cpp, 3307, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) MFilesSession.cpp, 1798, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) RPCMethodCallWithRetry.h, 148, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) RPCMethodCallWithRetry.h, 148, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) RPCLogin.cpp, 2129, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) RPCLogin.cpp, 1013, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) RPCLoginHelper.cpp, 1586, Authentication failed. (Account name: "(M-Files Server)") (0x8004001A) (M-Files 23.2.12340.6 2023-03-21T13:30:41.463Z)
Solution
The method cannot currently be used properly with scripts (such as event handler and workflow state action scripts) due to the following issue:
"Recalculate" in "MFServer" is an asynchronous operation because it might in some cases take a long time to complete. M-Files API hides the asynchrony by monitoring the ending of the background job and returns the control to the caller only after the "Recalculate" operation has finished. To monitor the background job M-Files API needs to perform another login operation to the server. The issue is caused due to the fact that the event handler is executed with a special login and the server does not accept that for the re-login. This means that the "Recalculate" operation basically cannot, for the time being, be used in the event handler. The operation is actually triggered and probably succeeds as well, but an error is however received every time.
The workaround is to confirm the recalculate succeeds then have the script ignore the error through a Try/Catch or similar.
