Discussions

Expand all | Collapse all

Question on custom button Javascript

  • 1.  Question on custom button Javascript

    Bronze
    Contributor
    Posted 02-16-2018 20:09
    I have a custom button (Startup) on a form (Client) that gets clicked from an embedded report (Client Services). It looks like this on the form:
    https://www.screencast.com/t/ooRhLeJaFac">https://www.screencast.com/t/ooRhLeJaFac">https://www.screencast.com/t/ooRhLeJaFac

    The button opens up an add record form on a child table to the Client Services table (Service Changes) and pre-populates a few fields. When the user clicks Save to add that child record, it returns control to the top of the calling form (Clients).

    And here's my current Javascript that is working well:

    "<a class='Vibrant Primary' href='" &
    URLRoot() & "db/" & [_DBID_SERVICE_CHANGES] & "?act=API_GenAddRecordForm" & 
    "&_fid_7=" & URLEncode("Startup") & 
    "&_fid_44=" & [Unique Primary Key] & 
    "&_fid_46=" & [Related ClientCode] & 
    "&_fid_47=" & [Related Service] &  
    "&z=" & Rurl() & 
     "'>Startup</a>"

    I'd like to be able to add two more pieces of functionality to this button:

    1) When it returns control to the calling form, it only goes back to the top of the form. This is a very long form with a lot of information on it, and I'd love to have it automatically jump back down to the embedded report it was called from.

    2) There's one other piece of logic I'd like to add to the button. Is there any way it can also open a specified URL (from another field in the calling record) and do it where it opens a new browser tab and leaves it open for the user to get to later, and immediately jumps into its current working logic which opens the add record form and when the user clicks Save, it returns control to the original calling form's embedded report section?


  • 2.  RE: Question on custom button Javascript

    Top
    Contributor
    Posted 02-16-2018 20:53
    If I'm following you correctly, I might have a suggestion.

    I'd use a pop-up window, (or a new tab), and then when the user 'saves' the new record, it saves and closes the tab, thus returning the user to the original section of the original form.


  • 3.  RE: Question on custom button Javascript

    Bronze
    Contributor
    Posted 02-19-2018 16:39
    The thing is, after that save and close, I need the original form to be refreshed to show the updated status from what the added record supplied. And, in addition, I also need the second piece of functionality described. I want the user to focus on adding that record and get back to the main form, but also have the added convenience of another tab or pop-up to supply them with an additional report for reference.


  • 4.  RE: Question on custom button Javascript

    Posted 02-16-2018 20:57
    Michael,

    I think that this would work as a formula URL button to position to a spot on the form.

    var text URLONE = URLRoot() & "db/" & [_DBID_SERVICE_CHANGES] & "?act=API_GenAddRecordForm" & 
    "&_fid_7=" & URLEncode("Startup") & 
    "&_fid_44=" & [Unique Primary Key] & 
    "&_fid_46=" & [Related ClientCode] & 
    "&_fid_47=" & [Related Service];


    var text URLTWO = urlroot() & "db/" & dbid() & "?a=dr&rid=" & [Record ID#] & "#JumpTarget";


    $URLONE
    & "&NextURL=" & URLEncode($URLTWO)



    Then you would have a formula Rich Text field on the form near where you want to jump to

    "<a name=JumpTarget></a>"


    But I see that Matthew also posted an answer and his method may be easier to try first.


  • 5.  RE: Question on custom button Javascript

    Bronze
    Contributor
    Posted 02-19-2018 17:07
    Thanks Mark. I've been playing with this, but I can't seem to get it to work. The part you left off is the html to make the button display:

    "<a class='Vibrant Primary' href='" & 

    and 

     & "'>Startup</a>"

    , and I'm not exactly sure where in the formula those parts go. From what I have right now, the button doesn't display correctly any more, and instead I get this for a display:

    <a class='Vibrant Primary' href='https://page1solutions.quickbase.com/db/bnbximvhc?act=API_GenAddRecordForm&_fid_7=Startup&_f...

    Here's the code I have so far:

    var text URLONE = "<a class='Vibrant Primary' href='" & URLRoot() & "db/" & [_DBID_SERVICE_CHANGES] & "?act=API_GenAddRecordForm" & 
    "&_fid_7=" & URLEncode("Startup") & 
    "&_fid_44=" & [Unique Primary Key] & 
    "&_fid_46=" & [Related ClientCode] & 
    "&_fid_47=" & [Related Service];

    var text URLTWO = URLRoot() & "db/" & [_DBID_CLIENTCODES]  & "?a=dr&rid=" & [Related ClientCode] & "#JumpTarget" & "'>Startup</a>";

    If( [Client Service Status] = "Never" or [Client Service Status] = "Former",

    $URLONE & "&NextURL=" & URLEncode($URLTWO),

     ""
     )


  • 6.  RE: Question on custom button Javascript

    Posted 02-19-2018 17:09
    My suggestion is to leave out the fancy vibrant button stuff and focus on getting a plain vanilla URL formula button working first.


  • 7.  RE: Question on custom button Javascript

    Bronze
    Contributor
    Posted 02-19-2018 17:24
    I have no need for fancy either, but I need it to look like a button and not display as the formula itself. How do I do that?

    Here's what it looks like now:
    https://www.screencast.com/t/Ar03o6E1El

    Here's what it should look like:

    https://www.screencast.com/t/WmNUsDODZVf


  • 8.  RE: Question on custom button Javascript

    Posted 02-19-2018 17:26
    The field type should be formula URL (not formula Rich Text) and you may give the button any label and color you like in field properties.


  • 9.  RE: Question on custom button Javascript

    Top
    Contributor
    Posted 02-19-2018 08:56
    >And here's my current Javascript that is working well:

    "<a class='Vibrant Primary' href='" &
    URLRoot() & "db/" & [_DBID_SERVICE_CHANGES] & "?act=API_GenAddRecordForm" & 
    "&_fid_7=" & URLEncode("Startup") & 
    "&_fid_44=" & [Unique Primary Key] & 
    "&_fid_46=" & [Related ClientCode] & 
    "&_fid_47=" & [Related Service] &  
    "&z=" & Rurl() & 
     "'>Startup</a>"
    That's the problem - there is no JavaScript in your code. You can acheive what you want using script. The above example uses the &z and undocumented formula function Rurl() to return to the prior page. I am afraid there is not way to force this redirection scheme to position you back to a particular scroll post after then API_GenAddRecordForm page saves and redirects.

    However, you can use the rl & RedirectURL parameters along with the IOL technique to navigate you back to the desired scroll position. I have a demo in preparation and will post it when I have some free time.

    This post may be of some help at least in understanding the variety of redirection schemes used by QuickBase:

    The Hunt for Redirection Parameters
    https://community.quickbase.com/quickbase/topics/the-hunt-for-redirection-parameters