Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

REST API Business Centra;: Unable to Insert Data into table due UserId

Posted on by 10
Hello, I am seeking assistance on the following:

I am working on a Business Central Extension. I have enabled REST API / Web Services via OAUTH 2.0 with the main goal of creating an retrieving data between BC and an app.

I am struggling to insert data into a specific table due to a validation check against the currently logged in user (UserId). Here's the specific error:




Here's the trigger excerpt (The last error is where the above is coming from):



The error: Error('UserID' + ' ' + '[' + UserId + ']' + ' has not been assigned to any employee. Please consult the HR officer for assistance'), is grabbing the User Name for the Microsoft Entra Application I created and enabled to allow for API calls to BC.



The Trigger is grabbing the User Name from the above User Information Sub section, and since that user information is not stored in the User table in Business Central, and it hasn't gone through some set ups, it will immediately fail the OnInsert trigger.

My question is, how can I change the User Information that is obtained in the API to something that I have in the User table in BC?

Or how can I add the above information to the User table in BC, so that it wont fail the check for the OnInsert?
 
  • Suggested answer
    Yi Yong Profile Picture
    Yi Yong 1,359 Super User 2024 Season 2 on at
    REST API Business Centra;: Unable to Insert Data into table due UserId
    Hello,
     
    I think something is not adding up here.
     
    The 'User ID' will always be 'SND BC API' because this user will be the one calling the API service.
    You are filtering HREmp to 'User ID', which doesn't add up because 'SNC BC API' should not be an employee or found in the HREmp table.
     
    Why not create a field on the APIPage and when you are posting to the API, you need to add the actual User ID to the body?
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans