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)

add range to from data-source init method

(0) ShareShare
ReportReport
Posted on by

 Hi there,

 I am trying to add range\s in the init method of a form, in order to force that form to open for the current user of the AX session. I must find a way to bind the EmplTable.emplId  to SysUserInfo.Id (in order to find the current user opening the session).

 Practically, when my form opens, it opens on the first record from the EmplTable, not on the current user for the session (currentUserId) .

 I also looked at this community post: 
https://community.dynamics.com/ax/b/makecreatereiterate/archive/2015/01/06/how-to-add-a-range-or-data-source-to-a-form-data-source

 The problem is that my EmplTable and SysUserInfo  do not have common fields.

 I managed to add the range for Empltable.EmplId, however, I don't fully understand how I can make the form to open on the currentUserId.

 My code is written in the init() method of the form data-source(EmplTable) and looks like this:

 

public void init()
{

    EmplId                   emplId;
    QueryBuildDataSource     dsEmplTable;
    Query                    query;
    ;
    emplId= Empltable.EmplId;
    query = new query();
    // info(strfmt("%1",emplId));

        super();
            dsEmplTable =query.adddataSource(tableNum(EmplTable));
            //add the range:
            dsEmplTable.addRange(fieldnum(EmplTable, EmplId));
}

I hope I clearly explained my problem :)

Please help. Thank you!

edit: my form updates info in some EmplTable fields, and that's why it should open on the current EmplId.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Did you assign the value to the range?

    Like:

    dsEmplTable.addRange(fieldnum(EmplTable, EmplId)).value(emplId);

    If the EmplId return a value if not you can use curUserId() to return the UserId.

  • Community Member Profile Picture
    on at

    Hi Tatiana,

    Thank you for your quick reply!

    I did assign the emplId value. As you can see in the capture, it does not return me the emplId.

    codecapture.JPG

  • Verified answer
    Community Member Profile Picture
    on at

    are you using the EmplTable in the Datasource?

    Or how are you returning the data from that table?

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi AlanPaul8806,

    You can use this code to find EmplTable of current user:

    EmplTable::find(SysCompanyUserInfo::find(curUserId()).EmplId);

  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I also already showed you EmplTable::userId2EmplId(curUserId()) in one of your previous threads (form not initializing from INFO class startupPost method x++).

  • Community Member Profile Picture
    on at

    Hi,

    Indeed, I'm using EmplTable as my ds.

  • Community Member Profile Picture
    on at

    Thank you Ievghen!

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