Expand all | Collapse all

Run script in a button

  • 1.  Run script in a button

    Posted 05-07-2017 15:01
    So I have a button called "Send".  Basically, when this button is pushed, it changes 2 fields. Here is the code:

    var text URLONE = URLRoot()& "db/" &Dbid()& "?a=API_EditRecord" & "&rid=" & [Job Number]
    & "&apptoken= xxxxxxx" & "&_fid_40=Work In Progress&_fid_102=Sent&_fid_150=Sent";
    var text URLTWO =  URLRoot() & "db/" & Dbid() & "?a=q&qid=22";
    & "&rdr=" & URLEncode($URLTWO)

    At the same time that this button is pushed, I want to run an external PHP script through the following command:

    ">http://notifications.plumbingjohannesburg.co.za/push.php?id=[DEVICE_ID]&title=New">http://weburlgoeshere.com/push.php?id=[DEVICE_ID]&title=New job&msg=You have a new job.

    What this does is trigger a push notification to a device where the [user] is the person logged into that device.

    Now I have 2 issues with this:

    1) Firstly how do I run that URL everytime the button is pressed?(im sure this is pretty easy)
    2) Secondly, where the [Device_ID] placeholder is above in the URL, I need it to fetch this from another table within the app.  Basically what is happening is, the push notification can only work if the device ID matches that on the logged in user.  The device ID has to be pulled from a seperate table in the App (which is updated everytime a user logs in).  The common link here is the [user] field.  to simplify:

    I need to lookup the [device_id] field in another table, using the [user] field in this table as the "common" field.  similar to an excel Vlookup.

    Its pretty complicated, but I hope this makes sense.

  • 2.  RE: Run script in a button

    Posted 05-07-2017 15:23
    If you have a table of userid where the key field is set to be the userid, then you can create a relationship to your table where the reference field on the right hand side is a field called [Current User]. That will be a formula User field with the formula

    Then lookup the Device ID.

    As for the web call, I suggest using a Webhook. I'm not much of an expert on external Webhooks, i.e. hitting a website outside of QuickBase, but that is exactly what they are designed to do.

  • 3.  RE: Run script in a button

    Posted 05-07-2017 15:30

  • 4.  RE: Run script in a button

    Posted 05-07-2017 16:35
    Webhooks wont work here because they only apply when the record is changed/added/delete etc. They wont work on a formula URL button either.  So the actual button has to include the script.

  • 5.  RE: Run script in a button

    Posted 05-07-2017 16:57
    The URL button is editing g a record. So why do you feel that you cannot trigger the Webhook by one of the fields being edited by the URL button.?

    You can even create a new field to be edited by the URL specifically to trigger the webhook

  • 6.  RE: Run script in a button

    Posted 05-07-2017 16:16
    Thanks for this.  The [user] in question is not the current user, but one that is selected from a user type field.  How will this affect the formula?

  • 7.  RE: Run script in a button

    Posted 05-07-2017 16:26
    Well, no problem. Just make that relationship and then the Userid will be selected from a drop down list manually. The lookup field from the relationship will then populate the Device ID.

    You can then wrap your URL in an IF statement to have it only calculate if your conditions are met.

  • 8.  RE: Run script in a button

    Posted 05-07-2017 16:29
    I want it to pull the info automatically without having to select from a drop down.  this is something that will happen in the background (hidden fields)

  • 9.  RE: Run script in a button

    Posted 05-07-2017 16:28
    basically, what I am saying here is that the relationship wont work, because the key field is not a user field (this cant change).  

    There must be some type of formula text field that I can create that is able to pull the data from 1 table to another without a relationship?

  • 10.  RE: Run script in a button

    Posted 05-07-2017 16:54
    Why can't you create a new table with the Key field being the User and match it to a user field in your Details table?

    By match it, I mean to use it as the reference field in a relationship.

    If you want this to be hidden from the user entirely, make a new formula called [Userid mirror] with a formula if

    [My userid field]

  • 11.  RE: Run script in a button

    Posted 05-08-2017 13:52
    If you are at a roadblock and are looking for one on one assistance, you can contact me via the information on my website. QuickBaseCoach.com