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

  • 0
  • 1
  • Question
  • Updated 7 months ago
  • Answered
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);"


Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb

Posted 7 months ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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);"

)



Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb
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


Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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);"

)

Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb
This is great - thank so much for your help!
Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb
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);")
(Edited)
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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]);


Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb
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....?

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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.
Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb
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.

Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 65,280 Points 50k badge 2x thumb
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
Photo of oliver mah

oliver mah

  • 930 Points 500 badge 2x thumb
ok, kind of thought that would have been the case.  Thanks for again for your insight and help.