how to set the current user language as range in x++ query

Hi All,

I want to set the current user language as range(addrange) in x++ query in d365fo

You can get the user language by using the function - currentUserLanguage()

public class Product extends FormRun


public void init()
Query query;
QueryRun queryRun;
QueryBuildDataSource ecoResProductds,docuRefds,ecoResProductTranslationds;
FormCommandButtonControl attachButton;
UserInfo userInfo;
SecurityUserRole securityUserRole;
SecurityRole securityRole;
const str MagicNumber = “Product”;
attachButton= this.control(this.controlId(#SystemDefinedViewEditButton)) as FormCommandButtonControl;
query = EcoResProductTranslation_ds.query();
ecoResProductTranslationds = query.dataSourceTable(tableNum(EcoResProductTranslation));
ecoResProductds = query.dataSourceTable(tableNum(EcoResProduct));
docuRefds = query.dataSourceTable(tableNum(DocuRef));
docuRefds.addDynalink(fieldNum(DocuRef, RefRecId),EcoResProduct,fieldNum(EcoResProduct, RecId));
docuRefds.addDynalink(fieldNum(DocuRef, RefTableId),EcoResProduct,fieldNum(EcoResProduct, TableId));

while select userInfo
join securityUserRole
where securityUserRole.User == userInfo.Id && userInfo.Id == curUserId()
securityRole = null;
select firstonly securityRole
where securityRole.RecId == securityUserRole.SecurityRole;

if (securityRole.Name == MagicNumber)


I have tired this method but form is taking 5 mins to open.

Does only using currentUserLanguage() function causing the delay?

Or other part of the code, i see a while in your method to disable and enable a button and that doesn’t sound well.

After removing the range for the laguage form is opening fast but after adding this range form is getting delay to open.

I want to enable and disable the edit button when the user having the particular role and also i want display the product attachment related to item of the current user language

Look at the method, it just fetches the language id from UserInfo table.

For that purpose you won’t need a while select statement,

select firstOnly Recid from securityRole where securityRole.AotName == ‘RoleNameHere’;
select firstOnly RecId from userRole where userRole.User == curUserId() &&
userRole.SecurityRole == securityRole .RecId;

if (userRole.RecId) {enable} else {disable}

Hi Kranthi,

I am unable to get the current user language from above query mentioned from you.