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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Make field value redistricted to lookup value

(0) ShareShare
ReportReport
Posted on by

I have a string field and I build lookup based some certain criteria. I need to restrict the value which may be entered directly from user ( not selected from lookup) to lookup values. 

I know that I can use validate method to validate field value , but I need to know if I can do this directly especially if I have complicated criteria build in lookup 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Hi maram fraij,

    Usually you have a query for a lookup. So you can reuse same query in validate method and check if this query returns something for value entered by user.  Ideally you can create a method that returns query and use it in lookup and validate methods.

  • maram fraij Profile Picture
    on at

    How can I use query to validate the value ? can you share some code

  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Let say you have a query already with table InventTable and your lookup is over ItemId.

    boolean ret = true;
    QueryRun qr;
    QueryBuildDataSource qbds = query.dataSourceTable(tableNum(InventTable));
    
    qbds.addRange(fieldNum(InventTable , ItemId)).value(queryValue(valueFromTheField));
    qr  = new QueryRun(query);
    
    if (!qr.next())
    {
       ret = checkFailed('Not valid');
    }
    
    return ret;
  • Suggested answer
    Heinz Schweda Profile Picture
    1,367 on at

    Hi,

    you may use the class SysLookupMultiSelectCtrl to build your lookup. Using this class you don't have to overwrite the lookup-method of you StringEdit field, instead you have to build your lookup in the init-method of your form.

    Using this class, the user has to use the lookup, he is not able to enter values manually. But maybe this is exactly what you want.

    See following simple example, hope it helps (LookupStringEdit has to be replaced with the name of your StringEdit-field).

    public void init()

    {

       Query query;

       super();

       query = new query();

       query.addDataSource(tableNum(CustGroup));

       SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(CustGroup)), fieldNum(CustGroup, Name)).value("*inter*");

       SysLookupMultiSelectCtrl::constructWithQuery(this, LookupStringEdit, query);

    }

    Regards,

    Heinz

  • maram fraij Profile Picture
    on at

    Hi Heinz,

    I need only one value to be selected so SysLookupMultiSelectCtrl cannot be used . is it applicable to make this control  accepts only one value?

  • Heinz Schweda Profile Picture
    1,367 on at

    Hi, sorry, i didn't realize that you only need one value. So my suggested code won't help you.

  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi Maram

    I think you are looking for the modifiedField method on table if its a global rule or else the modified method on the field of your form's datasource if its form specific logic. In there you can validate against the same criteria as your lookup and clear the value if its incorrect

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 26

#2
imran ul haq Profile Picture

imran ul haq 8

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 4 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans