Announcements
No record found.
Hi,
I have 2 lookup.
in the first lookup I displayed the users.
in the second lookup I want to display only the roles assigned to the that user.
How can I display these roles in lookup ?
*This post is locked for comments
For the second field, you need to create a lookup method. There you will use a query, and then you must pass the value of your first field as a range for that query.
Here you can see how to create a lookup method that uses a query: community.dynamics.com/.../ax-2012-create-lookup-in-x
I add this code but I don't get values in the second lookup:
public void lookup() { SecurityUserRole _SecurityUserRole; UserInfo _UserInfo; SecurityRole _SecurityRole; Query query; QueryBuildDataSource datasourceModule; QueryBuildDataSource datasourceLanguage; QueryBuildRange rangeElementType; QueryBuildRange rangeModuleId; SysTableLookup sysTableLookup; query = new Query(); datasourceLanguage = query.addDataSource(tableNum(SecurityRole)); datasourceModule = datasourceLanguage.addDataSource(tableNum(SecurityUserRole)); select User from _SecurityUserRole join _UserInfo where _SecurityUserRole.User == _UserInfo.id && _UserInfo.name == UserInfo_name.Text() join Name, aotName ,Description from _SecurityRole where _SecurityRole.RecId == _SecurityUserRole.SecurityRole; datasourceModule.addRange(fieldNum(SecurityRole, Name)).value(queryValue(_SecurityRole.Name)); sysTableLookup = SysTableLookup::newParameters(tableNum(SecurityRole), this); sysTableLookup.addLookupfield(fieldNum(SecurityRole, Name)); sysTableLookup.addLookupfield(fieldNum(SecurityRole, aotName)); sysTableLookup.addLookupfield(fieldNum(SecurityRole, Description)); //sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); }
Can you please explain why you are using the select statement,
1) Do you have any value in _SecurityRole.Name variable after the select statement is executed? If not, please re-evaluate your select statement.
2) This select statement can return multiple records (one for each of the user's roles). At the moment you pass only the first role as a range to your query. Instead you should use a while select statement, and add a range for each _SecurityRole record that you get.
3) You have commented out the line of code where you pass your query to the lookup ("//sysTableLookup.parmQuery(query);"). So your query has no impact on the lookup.
I use select satetement to get the roles from securityRole based on user selected on the first lookup.
1.yes I get values after the select stetement
2.I use while select statement
3.I use sysTableLookup.parmQuery(query);
but always I have the same issue. any values displayed in the 2 lookup
For some reason you have added two data sources for your lookup, but you only need one.
Also, I suggest using better names than "datasourceModule" and "datasourceLanguage".
This code works and filters the lookup so that it shows only System administrator role. Now you just need to add your select statement to it and add your ranges based on the select statement:
public void lookup() { Query query; QueryBuildDataSource qbds; SysTableLookup sysTableLookup; query = new Query(); qbds = query.addDataSource(tableNum(SecurityRole)); qbds.addRange(fieldNum(SecurityRole, Name)).value("System administrator"); sysTableLookup = SysTableLookup::newParameters(tableNum(SecurityRole), this); sysTableLookup.addLookupfield(fieldNum(SecurityRole, Name)); sysTableLookup.addLookupfield(fieldNum(SecurityRole, aotName)); sysTableLookup.addLookupfield(fieldNum(SecurityRole, Description)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); }
Hi BASMA!
Your code should looks like:
public void lookup() { SecurityUserRole securityUserRole; UserInfo userInfo; SecurityRole securityRole; Query query; QueryBuildDataSource datasourceModule; QueryBuildDataSource datasourceLanguage; SysTableLookup sysTableLookup; select id from userInfo where userInfo.name == UserInfo_name.Text(); query = new Query(); datasourceLanguage = query.addDataSource(tableNum(SecurityRole)); datasourceModule = datasourceLanguage.addDataSource(tableNum(SecurityUserRole)); datasourceModule.addLink(fieldNum(SecurityRole, RecId), fieldNum(SecurityUserRole, SecurityRole)); datasourceModule.addRange(fieldNum(SecurityUserRole, User)).value(queryValue(userInfo.id)); sysTableLookup = SysTableLookup::newParameters(tableNum(SecurityRole), this); sysTableLookup.addLookupfield(fieldNum(SecurityRole, Name)); sysTableLookup.addLookupfield(fieldNum(SecurityRole, aotName)); sysTableLookup.addLookupfield(fieldNum(SecurityRole, Description)); sysTableLookup.parmQuery(query); sysTableLookup.performFormLookup(); }
Hi Nikolaos, second lookup depends of user name.
I modified the code and it works now :)
public void lookup()
{
TableLookup = SysTableLookup::newParameters(tablenum(SecurityRole),this);
query = new Query();
qbds1 = query.addDataSource(tablenum(SecurityRole));
qbds2 = qbds1.addDataSource(tablenum(SecurityUserRole));
qbds2.joinMode(JoinMode::OuterJoin);
qbds2.addlink(fieldNum(SecurityUserRole, SecurityRole), fieldNum(SecurityRole, RecId));
while select User from _SecurityUserRole
join _UserInfo where _SecurityUserRole.User == _UserInfo.id && _UserInfo.name == UserInfo_name.Text()
join Name, aotName ,Description from _SecurityRole where _SecurityRole.RecId == _SecurityUserRole.SecurityRole
qds1.addRange(fieldnum(SecurityRole, Name)).value(queryValue(_SecurityRole.Name));
}
sysTableLookup.addLookupfield(fieldnum(SecurityRole, Name));
sysTableLookup.addLookupfield(fieldnum(SecurityRole, AOTName));
sysTableLookup.addLookupfield(fieldnum(SecurityRole, Description));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
Please use rich formatting and </> button to paste your code.
And in your code you don't need to use while select if you join SecurityRole to SecurityUserRole by inner join.
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.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
CP04-islander 39
Michel ROY 14
imran ul haq 8