URL button to approve a record on a table

  • 0
  • 1
  • Question
  • Updated 2 years ago
  • Answered
HI All,

I am trying to solve a problem where some users find the gird edit  and using a drop down box on a table to complicated to give there approval....

My thoughts is on the table of records there is a button the user to approve the record with out going into it. Also ideally not refresh the screen so they can go down the whole table with out having the screen reload but probably need to grey the button out once pressed. 



I am assuming I need to use a formula URL field but I have not used these before. I found a working example but not sure of all the areas to use. For example for URLRoot() & "db/" & Dbid() do I need to add the table address between the () and the table ID in the second brackets? I could also not work out how to make the button just say approve and show in green (small thing but makes it look good)


The table I am using is called; Records
Field to change is ID 50 and called DSM Approval (text multiple choice)
The edit needs to add Approved to the field. I cant use a check box as I need to replicate the button for rejected approvals as there are formula dependent fields based of this and the field needs to record all changes

any suggestions welcome.
Photo of James

James

  • 172 Points 100 badge 2x thumb

Posted 2 years ago

  • 0
  • 1
Photo of Matthew Neil

Matthew Neil

  • 31,478 Points 20k badge 2x thumb
If you want a button, without a refresh, using something like this will do it:

URLRoot() & "db/" & [_DBID_RECORDS] & "?a=API_EditRecord&rid="&[Record ID#]&"&apptoken=yourapptokenhere&_fid_50="&URLEncode(Approved)

Just keep in mind it will do the edit when clicked, but you will have to manually refresh to see the changes.
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,038 Points 50k badge 2x thumb
This code will make a boring grey button but it will not disturb the screen, but rather it will do a quiet pop up 

var text URL= URLRoot() & "db/" & dbid() & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_50=" & "Approved")
& "&apptoken=" & "XXXX";

"javascript:" &
"$.get('" & 
$url & 
"',function(){" &
"$.jGrowl('DSM Approved', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"

The 5000 means 5 seconds before the pop up fades away, you can adjust that.  The syntax of that last bit is kinda wild, so save it for future use.  :)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,038 Points 50k badge 2x thumb
P.S.  I'm not sure right now how to make that into a pretty button.  I would have to do some testing when I get a chance and I'm not sure there is a way.
Photo of James

James

  • 172 Points 100 badge 2x thumb
Thank you.

The first reply gives me a button that works once I added in "" around the wording but takes you to a

screen showing <qdbapi><action>API_EditRecord</action>
<errcode>0</errcode>
<errtext>No error</errtext>
<rid>2140</rid>
<num_fields_changed>1</num_fields_changed>
<update_id>1490628960113</update_id>

</qdbapi>

if not solvable how do I change the formula to refresh?

also how do I get the button to look green and just say Approve?
Photo of James

James

  • 172 Points 100 badge 2x thumb
Second option sound really interesting but I go an error when saving the formula after the  & "XXXX"; might be having a moment but what do I need to replace the XXXX with?
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,038 Points 50k badge 2x thumb
OK, fix this

var text URL= URLRoot() & "db/" & dbid() & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_50=" & "Approved"
& "&apptoken=" & "XXXX";

loose the bracket after approved.

I suggest that you go to the Properties for the Application and turn off "Require Application Tokens."

Then you can just do this

var text URL= URLRoot() & "db/" & dbid() & "?act=API_EditRecord"
& "&rid=" & URLEncode ([Record ID#])
& "&_fid_50=" & "Approved";

(you still need the rest of the code though - that javascript stuff
(Edited)
Photo of Matthew Neil

Matthew Neil

  • 31,478 Points 20k badge 2x thumb
The full, and cleanest formula, including the reload: (used in a formula URL field)
********
var text URL= URLRoot() & "db/" & [_DBID_RECORDS] & "?a=API_EditRecord&rid="&[Record ID#]&"&apptoken=replacewithyourapptoken&_fid_51="&URLEncode(Approved);

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

*****
remember to use your app token.  
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 53,038 Points 50k badge 2x thumb
Right,
Mathews code will refresh the page and mine will not.  So you can decide which meets your needs best.