Forum Discussion

AlinMihalcea1's avatar
AlinMihalcea1
Qrew Assistant Captain
8 years ago

On Click Counter

I'm looking for a way to crate a counter that will increment the value in a field by 1 each time I push a button. I was trying to do it by using API_EditRecord&rid but It's eluding me.
  • There are two issues you have to deal with.

    First, what page are you on and what is being displayed? You can press a button to increment the counter using script and the API but if the field value is being displayed on the current page you have to somehow deal with the issue of displaying the new value of the counter so as to not confuse your users.

    Second, you first need to get the current value of the counter from the page you are on or through the API then increment and save the counter using API_EditRecord.

    The script is simple but you have to define the workflow you want.

  • AlinMihalcea1's avatar
    AlinMihalcea1
    Qrew Assistant Captain
    Dan,
    I would be on the same page the increment will occur. Displaying the new number on the page is not that important because users will not need to see this field. The field will be used as a trigger for creation of a child record as well as being part of a text field on the child record we just created. A type of versioning, if you would.
  • Try this

    var number NewValue = [My counter field] +1;

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
    & "&_fid_99=" & ToText($NewValue);


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

    // replace the 99 with the field ID of the counter field.
     
  • If you want a message to the user with bout a screen refresh you can do this
    var number NewValue = [My counter field] +1;

    var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
    & "&_fid_99=" & ToText($NewValue);



    "javascript:" &
    "$.get('" & 
    $url & 
    "',function(){" &
    "$.jGrowl('Children have been added', {life: 5000, theme: 'jGrowl-green'});" &
    "});" &
    "void(0);
    • AlinMihalcea1's avatar
      AlinMihalcea1
      Qrew Assistant Captain
      It worked. I just needed to add the apptoken to it.
      Thanks Mark!
    • CarlosCarlos's avatar
      CarlosCarlos
      Qrew Assistant Captain
      Absolutely off topic, but are there other colors for jGrowl? Haven't managed any other than the "theme: 'jGrowl-green'
  • AlinMihalcea1's avatar
    AlinMihalcea1
    Qrew Assistant Captain
    Awesome! I got the best of the two worlds. The flat one and the oblate spheroid one :)

    Thanks for everything both of you guys do!
    It was awesome meeting you at Empower. For everyone else coming across this post the has not yet been to an Empower, I highly recommend it.
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      It is in Austin next year - I used to live in Austin and it is a great place.
    • AlinMihalcea1's avatar
      AlinMihalcea1
      Qrew Assistant Captain
      I will definitely be there. Austin is an awesome city.