Forum Discussion

NarayananKumbak's avatar
NarayananKumbak
Qrew Cadet
8 years ago

Return to previous location on a form after running a JAVA Script code and record refresh

I have a rather long form with multiple sections to organize 500+ data fields. When I click on a URL button that runs JAVA Script code to create child table records, update data fields in the main record, etc. and then refresh the main record, the form control goes to the beginning of the form. Is there any way I can redirect the control to the previous location on the form? I have tried the same with multiple tabs and it goes back to the first tab after update/refresh.
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    Here is a how you get the page refresh to put you into a section.

    It is a two step process.

    (1) Insert a text element to your form, in the section you want the reload to go. 
    I will call it 'MySection'.
    The text element needs to be the following;

    <a name=MySection></a>

    (Make sure you enable html).

    (2) in your formula URL button that has the ...

    function(){" &"location.reload(true);" &"});" & "void(0);"

    You need to swap out the "0" in the void section to be the following.

    window.location.href='#MySection'

    So the entire thing will look like:

    "javascript:" &
    "$.get('" & 
    $URL & 
    "', function(){" &"location.reload(true);" &"});" & "void(window.location.href='#MySection');"

    This isn't perfect, it jumps a little at the initial 'click' if you aren't exactly on the text element already.  And depending on the load time for child records, it could put you on the element, but the form 'grows' as all the child records are loaded.
    But it will get you close.  You can always play around with the positioning of your text element to see if that helps.