Forum Discussion

TreySmith's avatar
TreySmith
Qrew Member
6 years ago

Button that adds the total of a numeric field to another

I couldn't find a post with similar details, but apologies ahead of time if this is a duplicate.
I am wondering if it is possible, or more how to create a button that adds two fields together, but keeps the total in one of the fields. EX.
I have a Table - Cards. A field within the table is [Quantity]. I want to create a button, and a separate field ([Number to Add]?) I am trying to create a way to type in a number to the [Number to Add], click the button, and it will add this to the total quantity. I'm not the best with formulas, but any help or suggestions are appreciated!
  • There are a number of ways to do this.  
    1)  Form rule
    2)  Button
    and probably can use automations too, etc.

    The Form Rule method is probably the most straightforward to set up (and may work better for you) - but you can decide which to use.

    ====
    Table:  Cards, with the table alias [_DBID_CARDS] (you can find the Table Alias at the bottom of Advanced Settings)

    Fields:
    [Quantity] - numeric field
    [Number to Add] - numeric field
    [New Quantity] - Formula Numeric field, with the formula:  [Quantity] + [Number to Add]

    Application Token:
    - you may need this for your Formula URL button - you can create one or use an existing one under the Application settings > App Properties > Advanced Settings > Security Options > Manage Application Token

    ====
    Option 1:  Form Rule

    1)  Customize the form for Cards
    2)  Go to Dynamic Form Rules tab
    3)  Create a new rule
    4)  The rule:
    When the record is saved
    and all of the following conditions are true
    - Number to Add is not equal to 0
    - Number to Add is not equal to (blank)

    Action
    - change Quantity to the value in the field New Quantity
    change Number to Add to the value 0

    So if you're editing a Card - type the number in "Number to Add", and hit Save as normal.  Then the "Quantity" will be updated to the new quantity, and "Number to Add" will get reset to 0.

    ====
    Option 2:  Formula URL button

    1)  Add a new Formula URL button, with the following formula:
    - make sure to replace [_DBID_CARDS] and the application token with the values for your app
    - also - make sure to update _fid_6 and _fid_7 with the correct Field ID numbers for Quantity, and Number to Add
    - in this example the Field ID for Quantity is 6, which is why the URL parameter says _fid_6

    // URL to the current record in view mode
    var Text ViewRecordURL = URLRoot() & "db/" & [_DBID_CARDS] & "?a=dr&rid=" & ToText([Record ID#]);

    URLRoot() & "db/" & [_DBID_CARDS] & "?a=API_EditRecord" 
    & "&rid=" & ToText([Record ID#]) // editing the current record you're on
    & "&apptoken=" & "REPLACE ME" // apptoken to make API calls
    & "&_fid_6=" & ToText([Quantity]+[Number to Add]) // update [Quantity] to new value
    & "&_fid_7=0" // reset [Number to Add] to 0
    & "&rdr=" & URLEncode($ViewRecordURL)  // redirect to the current record in View mode

    This button will edit the current Card record and update the Quantity to the current Quantity + Number to Add, and reset "Number to Add" to 0, and then redirect to a view only version of the current Card.

    ====

    Online help for API_EditRecord
    https://help.quickbase.com/api-guide/edit_record.html

    Online help for Application Tokens
    https://help.quickbase.com/user-assistance/app_tokens.html


  • Thanks Xavier! This is great(: I knew I was overlooking something. I had forgotten about Form Rules haha