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 :
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,827 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,827 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,827 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,827 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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans