web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Get selected UserID, X++ ?

(0) ShareShare
ReportReport
Posted on by 159

Hi everyone,
I want to take the current USER ID from selected form:

/System administration/Common/Users -> select user ->
6471.ax.jpg

I need a code like this : curUserId(); , but that doesn't work.

For example, I have 20 users and I want to open the form for each one separately, all the way the method takes me differently(from the selected one).

Form name : SysUserInfoDetail

Thank you !

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    CurUserId() returns the user id of the current user who is running the code. It has nothing to do with what is selected on this or other forms.

    If you are developing on SysUserInfoDetail form, you can get the user id of the active record simply by "userInfo.Id".

  • Vladislav Profile Picture
    159 on at

    That's right, but I want to execute my code in another form and just hang it for it with a button. I can't access the code from SysUserInfoDetail .

    So I execute my form :  

    SysUserInfoDetail  -> CommandButton -> method ->

    void clicked()
    {
        Args args;
    
        FormRun formRun;
    
    /* str test; ; test = userInfo.Id; */ args = new Args(); args.name(formstr(TestMultiLookup)); formRun=new FormRun(args); formRun.run(); formRun.wait(); }
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    It should definetely work.

    I tried to add a command button in SysUserInfoDetail form.

    void clicked()
    {
        info(UserInfo.id);
        super();
    }

    Then I added this logic in the clicked button. And it will show the selected user id whenever I click the button.

    Maybe you could explain your business requirement and the problem in more detail.

  • Vladislav Profile Picture
    159 on at

    1832.ax1.jpg

    This code is in a form created by me with name "TestMultiLookUp".

    I want to execute first "SysUserInfoDetail" and when click button in "SysUserInfoDetail" run this code. These are two separate forms and how to reuse the code from one to the other. I want to take the ID for example as you said "userInfo.Id" from SysUserInfoDetail and reuse the code(insert) in "TestMultiLookUp" -> "str 50 nameOfPerson"(assign in this variable).

    Thank you !

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    I'm sorry, I don't understand what you are trying to do. Maybe you could try to explain your business requirement or functional requirement.

    Anyway if you want to iterate all users (previously you were talking about selected user) your clicked method on SysUserInfoDetail should look like this:

    void clicked()
    {
        UserInfo userInfoLocal;
    
        while select userInfoLocal
        {
            info(userInfoLocal.Id);
        }
    }


    That would print the id of every user of the system in the infolog. Then you should just replace the infolog printing with anything you want to do for all these users.

  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    And you can't reuse code between forms. If you want to achieve that, put your code in a class that you can call from different forms.

    However you can call method of one form from another form: devexpp.blogspot.com/.../calling-methods-on-caller-dynamics-ax.html

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans