Forum Discussion

AndreonnaGarret's avatar
AndreonnaGarret
Qrew Assistant Captain
8 years ago

Formula Text Button that opens in a new tab

I have a formula text button that I need to open a child record in a new tab when clicked. Can someone please help me out?

My formula is:

var text rdr = URLRoot() & "db/" & [_DBID_ASSETS] & "?a=API_GenAddRecordForm"&
"&_fid_112=" & URLEncode ("Part") &
"&_fid_162=" & [Sales Order #] &
"&_fid_338=" & URLEncode ([Record ID#]) &
"&_fid_14=" & URLEncode ([Related Part Assignment]);

var text url =

  URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
    "&rid=" & [Record ID#] &
    "&apptoken=biyf682cpfpeqfbfpv8pida6k3gy" &
       "&_fid_142=true"&
       "&_fid_101=" &Now();


If(IsNull([Exchange Received])=false and [Line Type]="Part" and [Type]="Exchange",
"<a class=\"Vibrant Primary\" href=\"javascript:" & "$.get('" & $url &
    "', function(){" & "window.location.href ='" & $rdr & "';" & "});" &  
    "void(0);\">Receive Exchange</a>",
If([Exchange Received]=true and [Line Type]="Part" and [Type]="Exchange",
"<a class=\"Vibrant Success\" href=\"javascript:" & "$.get('" & $url &
    "', function(){" & "location.reload();" & "});" &
    "void(0);\">Exchange Received</a>"
))
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    href='"&$URL&"' target='_blank'

    The blank target will use the browser default (which is usually a new tab)
    • AndreonnaGarret's avatar
      AndreonnaGarret
      Qrew Assistant Captain
      This more or less made the button not work at all. Can you tell me if this is in the right spot?

      If(IsNull([Exchange Received])=false and [Line Type]="Part" and [Type]="Exchange",
      "<a class=\"Vibrant Primary\" href=\"javascript:" & "$.get('" & $url &
          "' target='_blank' , function(){" & "window.location.href ='" & $rdr & "';" & "});" &
          "void(0);\">Receive Exchange</a>",

      If([Exchange Received]=true and [Line Type]="Part" and [Type]="Exchange",
      "<a class=\"Vibrant Success\" href=\"javascript:" & "$.get('" & $url &
          "', function(){" & "location.reload();" & "});" &
          "void(0);\">Exchange Received</a>
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    Sorry for the confusion.

    Your current href is designed to refresh the page, correct?  (window.location .... void)

    you will replace all of that with the simple href="'& $URL &'" target='_blank'

    So it will preform your edit, but then open the rdr in a new tab.

    "<a class=\"Vibrant Primary\"
    href='" & $url & "&rdr=" & URLEncode($rdr) & "' target='_blank'
    >Receive Exchange</a>
    • AndreonnaGarret's avatar
      AndreonnaGarret
      Qrew Assistant Captain
      This works! Is there a way to get it to also save the parent record? When I clicked it opened a new tab, but left the original page as is unsaved. 
    • MCFNeil's avatar
      MCFNeil
      Qrew Captain
      For that you will want to use the 'linkaway' href call.  

      This is straight out of a template application:


      "<a  class='Vibrant Success' href='javascript:LinkAway(\"" & URLRoot() & "db/" & Dbid() & "?a=dbpage&pagename=success.html" & "\");' >Submit and redirect</a>"

      // This works because you have turned on the table's advance settings, "Save parent record automatically when a child record is created."

      yours will look like 
       href='javascript:LinkAway(\"" &$url & "&rdr=" & URLEncode($rdr) & "\");' target='_blank'
    • MCFNeil's avatar
      MCFNeil
      Qrew Captain
      now that I'm thinking about it, that might not work.... 
      The javascipt and the target might fight each other.... 

      I've never had to do it this way and the syntax is probably wrong... 
  • MCFNeil's avatar
    MCFNeil
    Qrew Captain
    I think a good user experience would be to have the button, do the edit, and rdr to the new form all in the same window, BUT add the "nextURL" parameter.

    That way as soon as they click the "save & Close" it sends them back to the PO where they started.

    Sometimes opening new tabs throws people off because they forget to close them, and still don't know where they end up.
    • AndreonnaGarret's avatar
      AndreonnaGarret
      Qrew Assistant Captain
      I completely understand your point. However, I was specifically asked to have it open in a new tab. The main user of this button may take a minute to be able to complete the information that opens in the new tab.