Skip to main content
Question

Magic Button to stamp current record and add new record fully

  • September 28, 2019
  • 0 replies
  • 150 views

Hi All, 

I realize this is pretty simple, but haven't been able to find this use in the community posts. What I'm looking to do is have a magic button that when clicked does the following tasks:
- edits a field on the record with the user that clicked it
- then adds a record in another table with info from fields in the current record.

The difference between other posts is I don't want the new record to open up during the add for the user to continue filling out, I only want the record added. 

For reference, I'm doing this because there is not only a separation of the process needed but also needing to make sure I convert formula results into simple values on the second table/record so they can only be manually edited and not adjusted based on a future formula adjustment. 

Thank You!

------------------------------
Chris
------------------------------
This topic has been closed for replies.

MarkShnierYou
Forum|alt.badge.img+24
I have put an app in the exchange which talks about how to make URL formuals, called URL formula for Dummies.  There is also the famous Quick Base Evangelist Kirk Trachy's app called Magic Buttons in the Exchange.

But I'm in the mood so here is everything you need to know in one post for a low code no code pages solution for us dummies.

Here is an example of how to next URL formuals when you need to do successive steps.  The nice thing about URL formuals as opposed to Automations, is that they happen right away so they can give a better user experience as you may be in a situation where the record is saved and refreshed before the Automation has a chance to act.  Also right now Automations do not Copy when you Copy and app.  But I often myself forget how much can be accomplished with Automations, which are no code.  So Automations do deserve honourable mentions as a tool.

OK, but back to URL formuals.  When you use a URL formula you need to do something at the end to either refresh the page or land the user on a report or a record, or else the system will feel compelled to spit out on the page the XML response to the last update - and even if successful it leaves the user no where and blurts what will look like an error message on the screen..


I always use formula variables as good practice to keep the code readable. Keep in mind that you may be the pour soul 5 years from now trying to remember what that button is doing.  So you want to keep the code KISS.

Once you have defined the formula variables you nest them like this.  So if you needed to do three things like edit, then add, and the land the user on display a record then you take three slices off the salami below.


$URLONE
& "&rdr=" & URLEncode($URLTWO)
& URLEncode("&rdr=" & URLEncode($URLTHREE))
& URLEncode(URLEncode("&rdr=" & URLEncode($URLFOUR)))
& URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLFIVE))))
& URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSIX)))))
& URLEncode(URLEncode(URLEncode(URLEncode(URLEncode("&rdr=" & URLEncode($URLSEVEN))))))

Here is an example

var text AddRecord =
URLRoot() & "db/" & [_DBID_PO_DETAIL_LINES]
& "?act=API_AddRecord&_fid_6=" & URLEncode ([Purchase Order])
& "&_fid_17=" & [Qty]
& "&_fid_10=" & [Related Priced Material];

var text DeleteRecord =
URLRoot() & "db/" & [_DBID_PO_DETAIL_LINES]
& "?act=API_DeleteRecord&rid=" & [Record ID#];

var text DisplayRecord=
URLRoot() & "db/" & [_DBID_PURCHASE_ORDERS]
& "?a=dr&rid=" & [Purchase Order];

If(Nz([Unit Cost])=0 and [Current Cost]>0,
$AddRecord
& "&rdr=" & URLEncode($DeleteRecord)
& URLEncode("&rdr=" & URLEncode($DisplayRecord)))


note that if you have application tokens enabled, you will need a line inserted like

& "&apptoken=xcxcxcxcxcxcxcxcxcx"

so like this

var text AddRecord =
URLRoot() & "db/" & [_DBID_PO_DETAIL_LINES]
& "?act=API_AddRecord&_fid_6=" & URLEncode ([Purchase Order])
& "&apptoken=xcxcxcxcxcxcxcxcxcx"
& "&_fid_17=" & [Qty]
& "&_fid_10=" & [Related Priced Material];


So that work fine, except its often nice to have a button which will work on a record or a report even a button on an embedded child report on a record so that the button is not specific to where the user is and you just want to click and refresh the page they are on.

So this will work.  It runs the URL formula variable and refreshes the page.

var text URL = .........;

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"


So the last issue is if you want the URL to do multiple steps (multiple API calls) and then refresh the page (record or report or even dashboard page) using the javascript.

I do not have the definitive answer to that.  I'm pretty sure that if you nest the URL calls "too" deep then the javascript refresh method will not work.  But I think that two deep may work. I'm actually not 100% sure of the limits.

So this might works, and you can try it and report back as you are trying to do 2 steps and refresh the page.

var text URLONE = .....;
var text URLTWO = ....;

var text URL = $URLONE
& "&rdr=" & URLENcode($URLTWO);

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"

Almost Lastly, if you do not want to refresh the page but just put up a quiet green fade way pop up, then use this for the javascript for a 5,000 millisecond pop up.

"javascript:" &
"$.get('" &
$url &
"',function(){" &
"$.jGrowl('This Item has been put on PO CANCEL snooze', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"

and Last lastly, if you need to run a URL formula variable called URL and then refresh the page but want to have a 2 second delay to allow and Automation time to complete before displaying he refreshed page 

"javascript:" &
"$.get('" &
$URL &
"',setTimeout(function(){" &
"location.reload(true);" &
"},2000));"
& "void(0);";




   


------------------------------
Mark Shnier (YQC)
Quick Base Solution Provider
Your Quick Base Coach
http://QuickBaseCoach.com
markshnier2@gmail.com
------------------------------