Discussions

Expand all | Collapse all

button to update a field only when another field value = X

  • 1.  button to update a field only when another field value = X

    Posted 09-25-2018 17:56
    I'm trying to create a button where the user can push it to change a value in the field to one that is specified by the user.  however only when another field is equal to a certain value. the below code works just fine, however i now need to make it more specific where value in another field (multiple choice field) Field X = a certain value.

    trying to understand the URL for dummies but I just can't wrap my head around how to be more specific with the code below:

    var text URL = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]

    & "&_fid_352=" & URLEncode("true")
    & "&_fid_317=" & URLEncode ([Rate - Cost - GRI Total])
    & "&_fid_163=" & URLEncode ([Rate - Cost - GRI Total]);


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




  • 2.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 19:11
    No problem



    var text URL = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]

    & "&_fid_352=" & URLEncode("true")
    & "&_fid_317=" & URLEncode ([Rate - Cost - GRI Total])
    & "&_fid_163=" & URLEncode ([Rate - Cost - GRI Total]);

    IF([Another Field] = "X",

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

    )





  • 3.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 20:16
    so, can I then use the If statement to drill it down even more?  for example:

    IF([Another Field] = "X",
    [date field] = within the current and next month




  • 4.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 20:25
    Sure, an IF can be as long as you like.

    IF(
    [Another Field] = "X"
    and
    (FirstDayOfMonth([date field])=FirstDayOfMonth(Today())
    or
    FirstDayOfMonth([date field])=FirstDayOfMonth(AdjustMonth(Today(),1))),

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

    )



  • 5.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 21:01
    This is great - thank so much for your help!


  • 6.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 21:31
    so i've done this but for some reason the button won't show up even when i click display as a button, never ran into this before.

    var text URL = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&rid=" & [Record ID#]

    & "&_fid_77=" & URLEncode("[APL GRI Amount]");

    If([Cost - Carrier]="APL",

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


  • 7.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 21:35
    The button will be blank if the condition is not true.  ie if 

    [Cost - Carrier]="APL",

    is not true

    also this is incorrect

    & "&_fid_77=" & URLEncode("[APL GRI Amount]");

    needs to be

    & "&_fid_77=" & URLEncode([APL GRI Amount]);




  • 8.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 21:43
    maybe I worded the wrong then....I guess what i'm trying to achieve is the below to update only where [cost-carrier] = "APL"

    & "&_fid_77=" & URLEncode("[APL GRI Amount]");

    we have many records in our cost table under [carrier]="APL" and this button needs to add the [APL GRI Amount] for only those records. 

    I'm guessing the IF statement might not be the rate choice....?



  • 9.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 21:48
    I'm confused.

    Can you say in plain English what condition need to be true to have the button update the single record that you are on.


  • 10.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 22:18
    I'm trying to update all costs in our system that where the carrier is "APL" with this button

    The current Table has 2 fields:

    1) url formula field - button to action the amount
    2) Numeric Field - the amount that will be entered into Field #77

    user enters in the amount and then clicks the button and all costs where the carrier is "APL" now has the value that the user entered into in #2 above.

    Hope this clarifies a bit.



  • 11.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 22:24
    That button will only update a single record.  Mass updating will require a different approach which is likely beyond the scope of what I can answer on this forum in detail.

    If you want to update all records, then you would need to use a saved table to table import and run that via an API_RunImport or else use an Action to update all the records. 

     You may want to contact me off line for one on one assistance if you are lookingfor a mass update.

    QuickBaseCoach.com


  • 12.  RE: button to update a field only when another field value = X

    Posted 09-25-2018 23:12
    ok, kind of thought that would have been the case.  Thanks for again for your insight and help.