I am working on an extension for BC, my task was to enable REST API services for that extension. I had created the Azure Application and connected it to BC via the Microsoft Entra Applications Page.
The issue that I am running into is that, some validation is required before data is entered into a table on BC. One of the validation checks is against the currently logged in user.
The validation check gets the user name of the user account that is logged on to the current session. Here's a snippet of the code:
Screen shot:
Code snippet:
trigger OnInsert()
begin
/* Reset Filters */
HREmp.Reset;
/* Set Filter for "Employee UserID" where it is equal to the user name of the user account that is logged on to the current session. */
HREmp.SetRange(HREmp."Employee UserID", UserId);
if HREmp.Find('-')then begin
/* Other Code */
end
else /* If the seatch fails, throw the error below */
begin
Error('UserID' + ' ' + '[' + UserId + ']' + ' has not been assigned to any employee. Please consult the HR officer for assistance')end;
end;
When I try to insert a record into the above table via the API, the UserId will be set to a value that isn't in the Users table in BC, which will fail the if check, which will fail the insertion of data. Here's the error snippet from the API:
{
"error": {
"code": "Authentication_InvalidCredentials",
"message": "The server has rejected the client credentials. CorrelationId: 67626907-e975-47e5-a1fe-fb3d892e4bd5."
}
}
So my question is, can I change the UserId that is passed in from the API to another one?
Any assistance on this is appreciated.