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 :
Service | Customer Service, Contact Center, Fie...
Suggested Answer

Email message setFocus() issue

(1) ShareShare
ReportReport
Posted on by 2
Recently a change in the code has been introduced (only in our production environment): EmailIntelligence/EmailSentiment/msdyn_EmailSentiment.js
This happens for all emails, both when choosing reply and also creating an email from blank.
The block of code appears at rows 434-444 and sets the focus from the body to the "To" field instead, resulting in annoyance from the business.
I'd prefer to avoid solving this with a script changing the focus after this code has been run, any ideas how to fix?
 
Said block of text in the file is this:
            // Set focus to the "To" field for new/draft emails so the focus order
            // follows the logical visual layout (To -> Cc -> Subject -> Body).
            var formType = formContext.ui.getFormType();
            var statusCodeAttr = formContext.getAttribute("statuscode");
            if (formType === 1
                || (formType === 2 && statusCodeAttr && statusCodeAttr.getValue() === 1)) {
                var toControl = formContext.getControl("to");
                if (toControl) {
                    toControl.setFocus();
                }
            }
This appears in the function EmailIntelligence.
 
Below is the difference in code, left is dev and right is prod:
I have the same question (0)
  • Suggested answer
    Assisted by AI
    ANInnoSolutions Profile Picture
    534 on at
    Hi HenrikFranzen,
     
    1) Issue
    In Dynamics 365 Customer Service, after a recent change introduced in production, the email form behavior has changed:
    - When creating or replying to an email, focus is automatically set to the "To" field
    - This overrides the expected behavior where focus remains in the email body
    - The issue affects all email scenarios (new and reply)
    - This causes user disruption and inefficiency

    The behavior is caused by code in:
    EmailIntelligence or EmailSentiment msdyn_EmailSentiment.js

    Specifically:
    - A block of code forces focus to the "To" field using setFocus

    2) Reason
    From the code:
    - The logic explicitly sets focus to the "To" field for:
    - New emails formType equals 1
    - Draft emails formType equals 2 with status equals Draft
    - This is intentional and part of: Email Sentiment or Email Intelligence enhancements

    The purpose of this logic:
    - Enforce a specific tab order:
    To then Cc then Subject then Body

    However:
    - This change overrides the existing user experience
    - It is not configurable via standard settings

    3) Resolution
    Option 1: Override using custom script
    - Create a custom JavaScript on the email form
    - Register on form OnLoad event
    - Use delayed execution to reset focus to body field

    Example approach:
    setTimeout(function () {
    var bodyControl = formContext.getControl("description");
    if (bodyControl) {
    bodyControl.setFocus();
    }
    }, 500);

    Option 2: Adjust execution order
    - Register custom script after Microsoft library
    - Ensure it runs last in execution pipeline

    This reduces need for long delay timing.

    Option 3: Disable Email Intelligence features
    - If acceptable, disable:
    - Email sentiment
    - Email intelligence

    Navigation:
    - Settings then Email configuration
    - Disable relevant features

    Note:
    - This may remove additional functionality
     
    For a more detailed answer, please provide more information.
     

    Rg,

    Alexander

    *Due to the complex and different possibilities of deploying Dynamics 365 I highly recommend not to setup the application without some expert/partner or support. (For more information contact me under anassl@inno-solutions.info or visit www.inno-solutions.de)

    *The Information comes directly from the manufacturer or provider and are validated (not guaranteed) up to date of creation of the posting.

    References:

    1. Microsoft Licensing Guide
    2. Microsoft Doc`s/Learn

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 51 Super User 2026 Season 1

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 51 Most Valuable Professional

#3
Nagaraju_Matta Profile Picture

Nagaraju_Matta 50

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans