Discussions

Expand all | Collapse all

Setting a Default button to add default values across multiple fields.

  • 1.  Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Hey Everyone,

    I have another question that I can't seem to figure out. Is there a way that I can add a button to my form that will auto-populate fields with default values, but the user can change if needed. I have a form that has 28 fields that take a # of employees. I'd like to be able to set defaults since these numbers won't change often, but when they do, the user can manually input a different number. Is this possible to do within quickbase?

    Thanks,​

    ------------------------------
    Alex Bennett
    ------------------------------


  • 2.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    You can use API_EditRecord in a URL Button, like this:

    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
    "&rid=" & [Record ID#] &
    "&apptoken=token" &
    "&_fid_6=& "value" & 
    "&_fid_7=" & "value" & 
    "&_fid_8=" & "value" & 
    "&rdr=" &
    URLEncode(URLRoot() & "db/" & Dbid() &
    "?a=dr&rid=" & [Record ID#])

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 3.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    I'll see if I can give that a shot. 

    Thanks!!

    ------------------------------
    Alex Bennett
    ------------------------------



  • 4.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Hey Ahuva,

    Could you give me some tips on getting this set up? I've got the API Call set up and created an app token, changed the fid's to the desired values, but getting errors for invalid input (Code 2). Will this allow me to create a button that will add these values to the fields I select?

    Thanks,

    ------------------------------
    Alex Bennett
    ------------------------------



  • 5.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Can you show me your code and the error messages?

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 6.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" & "&rid=" & [Record ID#] & "&apptoken=uw4jq7b9wmt6ybm59yqvc2dzpdj" & "&_fid_53=" & "3" & "&_fid_60=" & "3" & "&_fid_67=" & "2" & "&_fid_74=" & "2" & "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#])​

    ------------------------------
    Alex Bennett
    ------------------------------



  • 7.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
    "&rid=" & [Record ID#] &
    "&apptoken=uw4jq7b9wmt6ybm59yqvc2dzpdj" &
    "&_fid_53=" & "3" &
    "&_fid_60=" & "3" &
    "&_fid_67=" & "2" &
    "&_fid_74=" & "2" &
    "&rdr=" &
    URLEncode(URLRoot() & "db/" & Dbid() &
    "?a=dr&rid=" & [Record ID#])

    Sorry for the format...
    And this is my first attempt at an actual API Call within QuickBase so I apologize!

    ------------------------------
    Alex Bennett
    ------------------------------



  • 8.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    If the fields you're trying to edit are numeric fields, it might help to write the URL this way, as the extra ampersands and quotations aren't technically necessary for numeric values.

    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" &
    "&rid=" & [Record ID#] &
    "&apptoken=uw4jq7b9wmt6ybm59yqvc2dzpdj" &
    "&_fid_53=3" &
    "&_fid_60=3" &
    "&_fid_67=2" &
    "&_fid_74=2" &
    "&rdr=" &
    URLEncode(URLRoot() & "db/" & Dbid() &
    "?a=dr&rid=" & [Record ID#])

    If that doesn't help, did the error message provide you with any details other than the error code?
    I'm assuming the message looked something like this. Was there anything specified in the <errdetails> tag?

    <qdbapi>
    <action>API_EditRecord</action>
    <errcode>2</errcode>
    <errtext>Invalid input</errtext>
    <errdetail>
    details
    </errdetail>
    <rid>rid</rid>
    <num_fields_changed>0</num_fields_changed>
    <update_id/>
    </qdbapi>


    ------------------------------
    Ahuva Brown
    ------------------------------



  • 9.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    <qdbapi>
    <action>API_EditRecord</action>
    <errcode>2</errcode>
    <errtext>Invalid input</errtext>
    <errdetail>Sorry, the data for the field named "Plumbing Close Duration" with field id 295 is too long.</errdetail>
    <rid>5</rid>
    <num_fields_changed>0</num_fields_changed>
    <update_id/>
    </qdbapi>


    ------------------------------
    Alex Bennett
    ------------------------------



  • 10.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Plumbing Close Duration is just another field that I don't want to make any changes to.

    ------------------------------
    Alex Bennett
    ------------------------------



  • 11.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    It's hard to say without looking at the data myself, but are you able to temporarily clear the data from "Plumbing Close Duration" and then test again? That way you'll know that your code works and it's a problem with a specific field. What kind of field is plumbing close duration? Is it possible that it's exceeding some sort of character limit? 

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 12.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    I'll attempt to clear and test to see. It is a Formula - Rich Text field to display duration based on formulas in the form.

    ------------------------------
    Alex Bennett
    ------------------------------



  • 13.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Ok, I got it working! It updates the fields I want with the values I want!

    How can I style my button so that it doesn't display my whole api call as text on the button?

    ------------------------------
    Alex Bennett
    ------------------------------



  • 14.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Nevermind, I got that as well! 

    Thanks for all your help Ahuva! You're awesome!!!

    ------------------------------
    Alex Bennett
    ------------------------------



  • 15.  RE: Setting a Default button to add default values across multiple fields.

    Posted 20 days ago
    Glad to hear!

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 16.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    Hey Ahuva,

    I wanted to ask your opinion, after setting up the button to auto populate data, it works great. However, when I try to add that schedule from a different table that's linked, it pulls me into that page to be able to click the button but I get an error if I'm coming from that table.

    <qdbapi>
    <action>API_EditRecord</action>
    <errcode>30</errcode>
    <errtext>No such record</errtext>
    <errdetail>Missing "rid" parameter.</errdetail>
    </qdbapi>

    Any Ideas on what might be my issue?


    ------------------------------
    Alex Bennett
    ------------------------------



  • 17.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    Could you describe the process to me in more detail?

    If I understood correctly, it seems to me that the cause of your issue is this part of the code: rid=" & [Record ID#] 
    That record ID is referring to the record that the button is being clicked on. If you're clicking the button on a different record than the one you want to change, you'd need to set it up slightly differently.

    If, say, you're on a table called Tasks, and you're trying to access or edit a record from the related Projects table, you'd need to do this: rid = " & [Related Project]

     I might have misunderstood your problem, so if this doesn't solve it, can you give me a more detailed explanation?


    ------------------------------
    Ahuva Brown
    ------------------------------



  • 18.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    The likely cause is trying to click the button on a record that is in ADD mode where the Record ID# does not yet exists.

    If you want to default in certain field values, then you should use form rules when in Add mode.

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



  • 19.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    No I think you're right. So I have a Schedules Table that I have put that button on. But the data comes from the Parent Table of Jobs, So when the company is in the process of creating a new job, they can add a schedule, then on the schedule page I've added that default values to save them time, so from there I can figure out how to display a calendar report of those jobs and their correct durations. The button works when I'm editing from the Schedules table, but If I'm on Jobs and click to add a schedule so it takes me to the Schedules table, that's where I can't use the button and get the error. I'll try changing my code to include [Related Project].

    ------------------------------
    Alex Bennett
    ------------------------------



  • 20.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    If you're trying to create a child record from a parent table which contains default values, you can do it this way, using API_AddRecord:

    URLRoot() & "db/" & [_DBID_SCHEDULES] //this is the table alias, which you'll find in the advances settings of the table on which you're creating the record, at the very bottom 
    & "?a=API_AddRecord" &

    "&apptoken=uw4jq7b9wmt6ybm59yqvc2dzpdj" &
    "&(fid of related parent record)=" &URLEncode ([Record ID#]) &

    "&_fid_53=3" &
    "&_fid_60=3" &
    "&_fid_67=2" &
    "&_fid_74=2" &
    "&rdr=" &
    URLEncode(URLRoot() & "db/" & Dbid() &
    "?a=dr&rid=" & [Record ID#])//this record id is the record where you want to redirect after creating the record

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 21.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    So is this possible to be able to add and edit the record at the same time? As in able to edit from the Schedules table to click the button, or click the button when adding from the Jobs Table?

    ------------------------------
    Alex Bennett
    ------------------------------



  • 22.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    You won't be able to use AddRecord to accomplish both things.

    The API_AddRecord button will create a new record on a specified table containing the specified default values.
    The API_EditRecord button will edit an existing record.

    Either button can be changed depending on where you're clicking the button from, by either using Dbid() or the table alias depending on whether you're adding or editing records on the current table or a different table. 

    For EditRecord the [record id] field will define which record you want to edit.

    It's possible to combine multiple API's within one button, if, for example, you want to edit the current record and then add new record somewhere else, as I've written below. It doesn't sound like that's what you're trying to do, though, so in your case it might be best just to have two different buttons, one button on the schedule record if you want to edit an existing schedule, and an AddRecord button on the parent table to add schedule records with default values.

    This is an example of a url that calls more than one API:

    URLRoot() & "db/" & Dbid() &
    "?a=API_EditRecord" &
    "&rid=" & [Record ID#] &
    "&_fid_6=1" &
    "&_fid_7=2"& 
    "&rdr=" & URLEncode(URLRoot() & "db/" & [_DBID_TABLE] & "?a=API_AddRecord&_fid_10=" & [Record ID#] & 
    "&_fid_8=3" & 
    "&_fid_9=4" &
    "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=dr&rid=" & [Record ID#]))

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 23.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    I was thinking 2 different buttons but I'm also confused on this process since I haven't worked in API calls before. Because from the Jobs Table, it just directs me to the Schedules Table anyways when I click Add Schedule. So I'm confused, since the button will show up both ways whether I'm editing from Schedules Table, or am directed there from Jobs Table. It just will only work one way or the other, and throw an error from the other.

    ------------------------------
    Alex Bennett
    ------------------------------



  • 24.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    You probably got an error because when you were redirected to the record when clicking on the Add Schedule button, the record was opened in edit mode and hadn't been saved yet, so the record id didn't yet exist. You can only use the Edit Record API on an existing record.

    For the existing Add Schedule button that is automatically generated when a relationship is created, you can just edit that field to input default values. The url will look similar to the AddRecord example I gave you, so you can just stick in the fid values yourself instead of creating a whole new button.


    ------------------------------
    Ahuva Brown
    ------------------------------



  • 25.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    The Add Schedule button probably looks like this:
    URLRoot() & "db/" & [_DBID_SCHEDULES] & "?a=API_GenAddRecordForm&_fid_ 6=" & URLEncode ([Record ID#])& "&z=" & Rurl()

    You can just add the values for additional fields after the record id.
    URLRoot() & "db/" & [_DBID_SCHEDULES] & "?a=API_GenAddRecordForm&_fid_ 6=" & URLEncode ([Record ID#])&
    "&_fid_6=1" &
    "&_fid_7=2"& 
    "&z=" & Rurl()

    (GenAddRecordForm is similar to AddRecord, it just opens the new record in edit mode rather than just creating, saving, and redirecting. z= & Rurl() redirects you back to the original record where you pressed the button after the new record is saved).

    ------------------------------
    Ahuva Brown
    ------------------------------



  • 26.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    I'll see what I can do! 

    Thanks again Ahuva!

    ------------------------------
    Alex Bennett
    ------------------------------



  • 27.  RE: Setting a Default button to add default values across multiple fields.

    Posted 19 days ago
    That Worked Ahuva! Now my users can still have these filled auto-populated whether they come from my Jobs Table or Schedules Table. 

    Thanks a Ton!!

    ------------------------------
    Alex Bennett
    ------------------------------