Formula Text Button that opens in a new tab

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
  • (Edited)
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>"
))
Photo of Andreonna

Andreonna

  • 1,040 Points 1k badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
href='"&$URL&"' target='_blank'

The blank target will use the browser default (which is usually a new tab)
Photo of Andreonna

Andreonna

  • 1,040 Points 1k badge 2x thumb
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>"
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
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>"
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
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'
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
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... 
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
Oh i see the issue with this now.  You are actually performing an edit of the record you are on.  So if you try to save, and edit and rdr, that might cause some issues. (especially with overriding data)

What is the problem you are trying to solve for.  That might help with a more focused approach.
Photo of Andreonna

Andreonna

  • 1,040 Points 1k badge 2x thumb
I'll tell the full story lol

So when we sell some parts, we require the customer to send us back the bad part as an exchange. This button is in a report for the line items on a PO. So when pressed it will refresh that page (which is actually the PO) to show that the exchange was received, and simultaneously open a new tab that will allow us to enter that new part into inventory.

The idea is to streamline the process a little bit. 

Thanks! 
Photo of Andreonna

Andreonna

  • 1,040 Points 1k badge 2x thumb
I think maybe I just need it to also refresh the original page. 
Photo of Matthew Neil

Matthew Neil

  • 31,698 Points 20k badge 2x thumb
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.
Photo of Andreonna

Andreonna

  • 1,040 Points 1k badge 2x thumb
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.