Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

SetFocus > working solution! But not for all fields!? (BC 19)

Posted on by 144

Our users sometimes have to enter hundreds of order items. To optimize the input, I was asked whether the cursor should positioned on the "No."-field for each New Record.

The following solution seems to work without any problems - but unfortunately not for every field. And I can't find out why.

Javascript:

Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('Ready','');

function SetFocusOnField(fieldNo)
{
    window.parent.document.querySelector(`[controlname^='${fieldNo}'] input`).focus()
}

PageExtension:

PageExtension 50323 "SalesOrderSubformEXT_HAL" extends "Sales Order Subform" //46
{
    layout
    {
        addlast(content)
        {
            usercontrol(SetFieldFocus; SetFieldFocus)
            {
                ApplicationArea = All;
                trigger Ready()
                begin
                    CurrPage.SetFieldFocus.SetFocusOnField('No.');
                end;
            }
        }
    }
    trigger OnNewRecord(BelowxRec: Boolean)
    begin
        CurrPage.SetFieldFocus.SetFocusOnField('No.');              // didn't work
        //CurrPage.SetFieldFocus.SetFocusOnField('Type');           // didn't work also
        //CurrPage.SetFieldFocus.SetFocusOnField('Quantity');       // but this works
        //CurrPage.SetFieldFocus.SetFocusOnField('Location Code'); // this - and many other fiels - working also
    end;
}


I can use SetFocus with many fields (e.g. "Location Code" and "Quantity")
But for the two fields "Type" and "No." it didn't work.

Does anyone have any idea how I can successfully move the cursor to the field "No."?

  • SetFocus > working solution! But not for all fields!? (BC 19)
    Maybe it's way too late for this reply, but in case you or someone visiting this page still need(s) a suggestion:

    I can't be sure, but maybe the problem is that you do not use the precise controlname referenced by 
     
    function SetFocusOnField(fieldNo)
    {
        window.parent.document.querySelector(`[controlname^='${fieldNo}'] input`).focus()
    }
    As you can see, the method above references some controlname. This, I believe has to be exactly the controlname as it appears in the HTML document loaded in the browser.

    In case of field "No.", try to leave out the "." which abbreviates the word. So simply try "No" - it's probable that the HTML document leaves out the "." in this case.

    In case of field "Type", I believe that it is once again a question of getting the right controlname. Maybe try "FilteredTypeField", as this is the name used in the Sales Order Subform for the most commonly used "Type" field - the one that is usually filled in by users. But you would have to verify that.

    Bottom line is you have to specify the precise controlname as it is present in the HTML document and from experience I can tell that in most cases this controlname is the name of the control as defined on the Page object (the first name you specify when you declare a field in a Page object). And that the HTML document usually drops the "." if this symbol is present in the name of the control in the Page object. 

    For example:
  • neckit Profile Picture
    neckit 144 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    I'm still looking for a simpler solution or hoping someone can figure out why the JS solution doesn't work with "No.". But I'll keep your first adjustment in mind as a workaround. Thank you for the ideas.

  • BrianDev Profile Picture
    BrianDev 105 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    There is a property on the fields QuickEntry.  They default to true on all fields.

    You can set the properties to false and then the page will skip them when tabbing thru fields.

    Not sure if this helps.

  • Suggested answer
    MahGah Profile Picture
    MahGah 15,428 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    Hi

    Thanks for info and that gave me a better idea. I cannot think about any solution. But that just reminded me of two customization that I saw before. I just share them here but I am sure they are not useful.

    1) I saw a company that added a second No field to remove the drop/down function of base field. Then made the No base field populate from this new field. they wanted to enter the number and not system shows them. Maybe you can use this method if new field let you focus on the new field No.

    2) I saw another company that they designed their own Lines sub page to do some development but then let that new Line subform populate bc base lines.

    Thanks

  • neckit Profile Picture
    neckit 144 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    For your understanding: there can be 5 item or 20 items or 10 items or 30 items per order. We have already created import pages for individual orders with even more items.

    We can't use Edit in Excel - but unfortunately it wouldn't speed up the input either.

    Often only a few fields are required for input, but unfortunately more fields are just as often required (e.g. the description + Price + other fields sometimes has to be changed and sometimes not).

    I don't think I have a chance with standard BC funds. In NAV 2013 we were able to solve this via WshShell and I was hoping that we could also do it via JS. And it would almost work - just not with No.

  • Suggested answer
    MahGah Profile Picture
    MahGah 15,428 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    Hi

    Just want to make sure I understand the challenge. Your team receive a SO with 100 items in it and they need to enter those order in BC. Hence, you are looking for faster "entry method" to enter these orders. 

    1) Is Edit in Excel and option? Like those orders have your part number or cross reference? This way your team can use Edit in Excel and copy and past. 

    2) Does your team only enter Item No and QTY? or something else. if it is only Item No and QTY is it possible to put the Item No as a first field and QTY as second. Then Exclude all other fields from Quick Entry? 

    pastedimage1656441529913v2.png

    pastedimage1656441474936v1.png

  • neckit Profile Picture
    neckit 144 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    Hi Brian,

    this is true for the last possible quick entry field. However, it is often not necessary to enter or change all the data in a data set. Then the down key is used, because otherwise you would have to press even more keys. Unfortunately, that doesn't solve our problem.

  • BrianDev Profile Picture
    BrianDev 105 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    This sounds like a training issue. Normally when you used the tab key instead of the arrow keys the new new record parks the cursor in the correct field.

  • neckit Profile Picture
    neckit 144 on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    Thanks for the hint but I can't find a way to use Yammer with dynamicsnavdev!

    When I go to the address, I'm on a login page. I can register there - but I don't receive an announced email confirmation (not even as spam). Or I can login with our company data and only get directly to our own yammer-pages but not to www.yammer.com/dynamicsnavdev.

  • Suggested answer
    Andy Sather Profile Picture
    Andy Sather on at
    RE: SetFocus > working solution! But not for all fields!? (BC 19)

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    I will open this up to the community in case they have something to add.

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans