Forum Discussion

DaneHughes's avatar
DaneHughes
Qrew Trainee
5 years ago

Home page URL in Button bar to autocreate record in a table

Hi,

I am trying to create a URL button in a home page button bar that will automatically create a record in a table. I found a post here saying to create it first in a formula field and remove the label to expose the link address to paste as the URL.

I did this and works greats as a formula field, but when using the link address on a homepage button I get the error. "Trying to add a non-unique value to a field marked unique. The field named "my_field" with field id XXX requires a unique value." What confuses me is that this field is not within or associated in anyway with the table_ID in which the record gets created.

Can anyone assist with this or explain why this is preventing a record from being created?

Formula field:
var text URL = URLRoot() & "db/" & [_DBID_MY_TABLE_ID] & "?a=API_AddRecord";
"javascript:" &
"$.get('" & 
$URL & 
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"

URL link address on homepage:
javascript:$.get('https://(company).quickbase.com/db/(MYTABLEID)?a=API_AddRecord',function(){location.reload(true);});void(0);

14 Replies

  • Are you trying to actually add a record, or just put up an add record form.  If you are trying to actually add a record, are there any fields you need filled in or did you want to, for some reason, create a blank record.  And furthermore, after a record is added, where did you want to land the user?

    If you are just trying to put up a button to open a form to add a record, then there is native functionality for that when you make a Dashboard button, no need for any code.

    • LauraThacker's avatar
      LauraThacker
      Qrew Captain
      I have noticed lately  a number of posts where newer Admins appear to be attempting to implement more complex Javascript-button functionality when they are simply trying to use standard Add and Edit functionality for which there are easier standard formula formats.
  • Thanks for a quick reply and yes this would just add a blank record, as crazy as it may sound, so I'm trying to make it as simple as possible for my users.
    Also, I'd like to just return the user back to the home page, which I believe the javascript will do fine.

    Appreciate the feedback.
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      OK, well who are we to question why you want to add blank records :)

      Where is says in your formula 

      [_DBID_MY_TABLE_ID]

      What you need to do is to go to the target table where the record is to be added and settings and advanced properties and at the bottom it will give the table ID such as

      _DBID_ORDERS

      That is what goes in the square bracket so the formula URL know which in which table to add the the record.
    • DaneHughes's avatar
      DaneHughes
      Qrew Trainee
      The correct DBID is in there, I just removed it from this example and replaced it with [_DBID_MY_TABLE_ID]
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      OK, well I doubt the error message is in error.  There must be a field named what the error message says in the table you are adding a record to.   Do you have the correct DBID?  ie are you adding records to the the table you intended.
  • OK, so I tried this and got a message that I could not embed Javascript into a URL button on a Home Page.  So I did this and it works.



    • DaneHughes's avatar
      DaneHughes
      Qrew Trainee
      Perfect. I did not get that message in my app. Thank you so much!