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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

how to add method to dataField in form extension?

(1) ShareShare
ReportReport
Posted on by 932

Hello,

I add create extension of form EcoResProductLifecycleState

I add new datasource , then I want to add lookup method to dataField of this dataSource : 

pastedimage1682583181131v1.png

have you any idea?

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 Moderator on at

    Hi, You can use on lookup control in form design (assuming you have added this field in form design)

    allaboutdynamic.com/.../

    If you want lookup of datasource field only then you can override it. Check this article.

    ievgensaxblog.wordpress.com/.../

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

    Hi Basma,

    There won't be lookup event handler at form DataSource field level. Lookup event handler will be available at form control level only.

    You can expand the control >> Events >. Copy the onLookup event and paste it in new class and add the lookup code there.

    Thanks,

    Girish S.

  • BASMA Profile Picture
    932 on at

    thanks for reply ,

    I want to add lookup on dataField not th control

    I want this structure  of the lookup method : 

     [DataField]
            class FieldLabel 
            {
               public void lookup(FormControl _formControl, str _filterStr)
                {
                    shipCreatorSetup.performLookupField(_formControl, ITMCreatorSetupTable, _filterStr);
                }
                }

  • GirishS Profile Picture
    27,843 Moderator on at

    If it's a custom form, you can override the field level lookup method. Navigate to that field >> Methods >> Override Lookup.

    If it's a standard form, you need to use control level lookup event handler.

    Thanks,

    Girish S.

  • BASMA Profile Picture
    932 on at

    its a standard form , how can I use the parameter "_filterStr" in eventHandler

    Because I have a method that contains this param

  • Mohit Rampal Profile Picture
    12,573 Moderator on at

    It's still not clear why do you want on datasource level only, you can create lookup on design level and cancel super call.

    Can you provide more details on method you are referring that contains parameter.

    We can create extension on datasource field level as well but I am not sure if lookup will work.

    dynamics365musings.com/.../

    There isn't lookup event handler for form datasource field.

  • GirishS Profile Picture
    27,843 Moderator on at

    You cannot create lookup at a DataSource field level if it's a standard form.

    Yes, the Lookup method will accept strFilter as a argument but in standard form there is no event handler available in form datasource field level.

    Try writing COC for the form data field control. 

    Thanks,

    Girish S.

  • BASMA Profile Picture
    932 on at

    because I add new method in custom class that contains filterStr as paramter  :  

    public boolean performLookupField(
            FormStringControl _formStringControl,
            MandatoryFieldsTable _mandatoryFieldsTable,
            Range _filterStr)
        {
            boolean         ok;
            FormRun         formRun;
            Args            args = new Args(formstr(MandatoryFieldsTableLookup));
        
            if (_formStringControl.lookupButton() == FormLookupButton::Always)
            {
                ok = true;
                rangeTableId = int2str(_mandatoryFieldsTable.TableNum);
        
                if (_formStringControl.hasChanged())
                {
                    rangeLabel = _formStringControl.text();
                }
                else
                {
                    rangeLabel = '';
                }
        
                this.buildAllFields(_mandatoryFieldsTable.TableNum);
        
                selectedRecord.setTmpData(allFields);
                select firstonly selectedRecord
                    where selectedRecord.Table_Id == _mandatoryFieldsTable.TableNum
                        && selectedRecord.Field_Id == _mandatoryFieldsTable.FieldNum;
        
                if (!selectedRecord)
                {
                    select firstonly selectedRecord
                        where selectedRecord.Table_Id == _mandatoryFieldsTable.TableNum
                            && selectedRecord.FieldLabel == _filterStr;
                }
        
                cursor = _mandatoryFieldsTable;
        
                args.caller(this);
        
                formRun = ClassFactory::formRunClassOnClient(args);
                formRun.init();
        
                _formStringControl.performFormLookup(formRun);
            }
        
            return ok;
        }

    then I will call this method in lookup of dataField like this   : 

     [DataField]
            class FieldLabel 
            {
               public void lookup(FormControl _formControl, str _filterStr)
                {
                    shipCreatorSetup.performLookupField(_formControl, ITMCreatorSetupTable, _filterStr);
                }
                }

  • GirishS Profile Picture
    27,843 Moderator on at

    Try like below.

    [ExtensionOf(formDataFieldStr(FormName, DataSourceName,FieldName ))]
    class ClassName_Extension
    {
        public void lookup(FormControl _formControl, str _filterStr)
        {
            super(_formControl,_filterStr);
            //add all your code here. You can use _filterStr variable anywhere in your code
        }
    }

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    12,573 Moderator on at

    You have two options to try, I shared before, try either creating extension class of form datasource field or create custom lookup method and use registerOverrides. Already shared both links in the first comment of this post. Let us know if both options doesn't work for you.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 461 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

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

#2
Subra Profile Picture

Subra 428

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans