Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Set cursor to beginning of field in editable grid

Posted on by 55

Due to some D365 system behavior, I'm trying to find a way to set the cursor to the beginning of a text field on editable grid control on selection. For now, I'm seeing I'm trying to see if setFocus will do it.

I've tried a number of versions of this code but I keep getting "Cannot read properties of null" or setFocus is not a function errors. 

function Grid_And_Form(executionContext) {
var formContext = executionContext.getFormContext();
var gridContext = formContext.getControl("Opportunities");
var myRows = gridContext.getGrid().getRows();
myRows.getControl("wc_nextsteps").setFocus();

}

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Set cursor to beginning of field in editable grid

    Hi DAcustom555,

    Here are some error in your code:

    1. gridContext.getGrid().getRows(); would return the collection of all your rows. Its return type is "Collection" which doesn't support getControl() function.

    getRows (Client API reference) in model-driven apps - Power Apps | Microsoft Learn

    Collections (Client API reference) in model-driven apps - Power Apps | Microsoft Learn

    2. Based on the API doc, grid cell doesn't support setFocus() method, please refer to this doc:

    GridCell (Client API reference) in model-driven apps - Power Apps | Microsoft Learn

    Here is a thread about getting sub grid by JS, you could have a look:

    Total amount of a dynamic filtered data in a sub-grid - Dynamics 365 General Forum Community Forum

  • DAcustom555 Profile Picture
    DAcustom555 55 on at
    RE: Set cursor to beginning of field in editable grid

    Thanks! When I use your example, it looks like it is not making it past the first if but completed with no errors. I do have values in many of the nextsteps field. Any ideas?

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Set cursor to beginning of field in editable grid

    Hi,

    First thing try to add if in every line to make sure the object is available which will help you to get rid of this null error.

    for example

    unction Grid_And_Form(executionContext) {

    var formContext = executionContext.getFormContext();

    if(formContext.getControl("Opportunities")!=null)

    {

    var gridContext = formContext.getControl("Opportunities");

    if(gridContext.getGrid()!=null)

    {

    var myRows = gridContext.getGrid().getRows();

    if(myRows.getControl("wc_nextsteps")!=null)

    {

    myRows.getControl("wc_nextsteps").setFocus();

    }

    }

    }

    }

    you can also try to timer but not sure if that will help

    carldesouza.com/.../

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans