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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Field focus changes when using setValue

(0) ShareShare
ReportReport
Posted on by 20

Hi!

I am struggling with the following: I use 'setValue' to change the value of an attribute using javascript. But when I do this the focus is automatically set to the changed field. Is there a way to prevent the system from changing the focus? I want to tab through my form and so this behavior really is getting in my way. Any ideas would be appreciated.

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    HI,

    You can use setfocus client script in JS to focus on control which you want.

    docs.microsoft.com/.../setfocus

    Add this code at the same place where you are using setValue.

    Please mark my answer verified if i were helpful

  • Community Member Profile Picture
    on at

    Hi Daniel,

    You can achieve it by using setFocus() function to set focus to the field that you need.

    1.Js code

    function focus(executionContext) {
        var formContext = executionContext.getFormContext();
        var test = formContext.getAttribute("new_test1").getValue();
        Xrm.Page.getAttribute("new_test2").setValue(test);
        formContext.getControl('telephone1').setFocus();
    }

    2.Test.

    When the field(test2) value is set, the phone field is focus in the form.

    pastedimage1600074512855v1.png

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans