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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to avoid user to type in lookup field using validation method

(0) ShareShare
ReportReport
Posted on by 30

I want to add the validation field so that user avoid to type in lookup field and type some garbage value that would not important for me to deal with.

pastedimage1667453782583v1.png

pastedimage1667453794557v2.png

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at

    Hi HammadAhmed,

    You need to write code in "validateField" method of the table and validate whether the value given in the lookup field.

    Just convert the query you have added in the lookup to select statement and validate the lookup field values.

    Also if the lookup field has a relation with the other tables - By standard it will give validation if you enter values other then values from the related table.

    Thanks,

    Girish S.

  • Suggested answer
    Arunraj Rajasekar Profile Picture
    1,743 on at

    Hi Hammad,

    You can accomplish this by using the validatefield method. Write a select statement to look for the record entered in the field; it will return false if the typed value is not found in the table.

  • HammadAhmed12 Profile Picture
    30 on at

    Kindly elaborate it by code

  • Arunraj Rajasekar Profile Picture
    1,743 on at

    Please see the blog below for sample.

    For custome table

    www.atnyla.com/.../909

    For extension table

    ztirom.at/.../

  • GirishS Profile Picture
    27,843 Moderator on at

    Refer to the below syntax for validateField method.

    Public boolean validateField(FieldId _fieldIdToCheck)
    {
        boolean ret;
        ret = super(_fieldIdToCheck);
        if(_fieldIdToCheck == fieldnum(YourTableName, YourLookupFieldName)
        {
            convert the lookup query to standard select statement.
            if(!bufferName.RecId) //if select statement doesnt return any buffer.
            {
                ret = checkFailed("throw warning");
            }
        }
        return ret;
    }

    Thanks,

    Girish S.

  • HammadAhmed12 Profile Picture
    30 on at

    pastedimage1667461036838v1.png

    I got syntax error

  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at

    You are missing one more bracket at if condition.

    Also where is your select statement for validating records?

    if(_fieldIdToCheck == fieldNum(tableName, fieldName))

  • HammadAhmed12 Profile Picture
    30 on at

    I didn't understand how to do select statement in this method

  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at

    You are adding a lookup from the table "Ui_EmployeesDept" and adding range to "operating unit number" field - value should be "00000011".

    Now on the table level validate field you need to add the select statement based on the above condition. Like below.

    Public boolean validateField(FieldId _fieldIdToCheck)
    {
        boolean ret;
        UI_EmployeesDept employeesDept;
        ret = super(_fieldIdToCheck);
        if(_fieldIdToCheck == fieldnum(YourTableName, YourLookupFieldName)
        {
            select fisrtOnly * from employeesDept
                where employeesDept.Name == this.Name
                && employeesDept.OMOperatingUnitNumber == "00000011";
            if(!employeesDept.RecId) //if select statement doesnt return any buffer.
            {
                ret = checkFailed("throw warning");
            }
        }
        return ret;
    }

    Thanks,

    Girish S.

  • HammadAhmed12 Profile Picture
    30 on at

    pastedimage1667623701127v1.png

    Now its givings me syntax error... Why?

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 April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 608

#2
André Arnaud de Calavon Profile Picture

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

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans