Skip to main content
Business Central forum
Suggested answer

How to change user id of current user on runtime in business central

editSubscribe (0) ShareShare
ReportReport
Posted on by 241

Hello experts,

Hope you're all doing well. 

I've a function "MyFunction(UserId: Code[50])" in a codeunit which further calls a system's function. In that system's function, code runs according to the current user that is currently logged in the business central. In 'MyFunction', I want to run that system's code according to the user I'm passing as a parameter.

In Finance and Operations, there is a method 'RunAs' which runs the code according to the user provided in the method 'RunAs'. Is there any way to perform this functionality in Business central? Answers will be highly appreciated. Thanks for reading.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 59,873 Super User on at
    RE: How to change user id of current user on runtime in business central

    Hi, Unfortunately, as far as I know, this feature is not available in BC.

    There is a clue, although I have not investigated in detail.
    In Job Queue, Codeunit or Report is executed using the User ID set on the card. I am not sure whether this can be used in our customization.

    pastedimage1643763275410v1.png

    Hope this will help.

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,714 Super User on at
    RE: How to change user id of current user on runtime in business central

    There is no such function in Business Central.

    But in Business Central you can assign permission to an object and that will allow users to run functions in the context of the object even though they will not be able to perform the same actions independently in the user interface.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 45,235 Super User on at
    RE: How to change user id of current user on runtime in business central

    that sounds like a great idea but I didnt know anything available in BC as of today.

Helpful resources

Quick Links

What Motivates a Super User?

We know many of you visit the Dynamics 365 Community and Power Platform…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,030 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,562 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Product updates

Dynamics 365 release plans