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

Set Focus on field

(0) ShareShare
ReportReport
Posted on by 383

Hellow everyone,

in the below screen i need to set focus on barcode Number once open the form and once add value to it set focus on Quantity filed and also once click enter to add new line and focus on Barcode Number

pastedimage1607260462269v1.png

I have the same question (0)
  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Ahmed,

    Have you tried controlName.setFocus()? For setting focus on the quantity field you can use the same statement in the modified method of the Bar code field.

  • AhmedSaeed Profile Picture
    383 on at

    The auto declaration property for the control is NO an i can't change  it

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Can You try this code to access the form control from the control name?

    public FormControl findFormControl(FormControlName _name)
    {
        int controlId = formRun.controlId(_name);
        FormControl control = formRun.control(controlId);
        return control;    
    }

  • Suggested answer
    AhmedSaeed Profile Picture
    383 on at

    Hi Gunjan,

    i solved the problem by the following code:

    1- to set focus on the field once the form opened i copy Activited event in form data source and add this code

    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]

       public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)

       {

           FormRun  fr = sender.formRun() as FormRun;

           fr.design().controlName(formControlStr(SalesTable,SalesLine_modItemBarCode)).setFocus();

       }

    2- to set focus on Quantity filed and  copy the Modified event for the control and add this code

      [FormControlEventHandler(formControlStr(SalesTable, SalesLine_modItemBarCode), FormControlEventType::Modified)]
        public static void SalesLine_modItemBarCode_OnModified(FormControl sender, FormControlEventArgs e)
        {
            FormRun  fr = sender.formRun() as FormRun;
            fr.design().controlName(FormControlstr(SalesTable,SalesLine_SalesQty)).setFocus();
        }

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 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans