Quickbase Discussions

 View Only
  • 1.  URL Formula Button w/ Two API Calls

    Posted 05-18-2022 18:50
    Edited by Aleisha Aldrich 05-18-2022 18:51

    I am working with 3 tables:

    • Parent Table: Work Orders-->
    • Intermediary (Child) Table: Subcontractor Quotes-->
    • Child Table: Status History.

    I have an embedded report on my Work Order form which displays the Subcontractor Quotes. I have a Formula-URL button displayed on the report called [Subcontractor Dispatched]. When the button is clicked, I need two things to happen:

    1. I need to create a record in the Status History Table. I've successfully accomplished this with the following formula:
    var bool show = If(Contains([Quote Status], "Approved by PM"),true,false); If($show=true,
    URLRoot() & "db/" & [_DBID_STATUS_HISTORY] & "?a=API_AddRecord&_fid_16=" & URLEncode ([Record ID#])& "&_fid_10=Subcontractor Dispatched" & "&_fid_11=Subcontractor Quote Status" & "&_fid_9=" & URLEncode(User()) & "&apptoken=xxxxxxxxxxxxx" & "&rdr=" &URLEncode ( URLRoot() & "db/" & Dbid() &"?a=doredirect&z=" & Rurl()),"")

     

    1. I need to update the related parent Work Order record by checking a checkbox field. However, I have two problems:
    A.) I can't seem to figure out how to denote which record to update in my formula. I've tried using the formula below but it returns an error stating >No such record< and >Missing "rid" parameter< (I assume it must be because the field [Related Work Order] actually exists in the Subcontractor Quotes table, not the Work Orders table):

    URLRoot() & "db/" & [_DBID_WORK_ORDERS] & "?a=API_EditRecord&_rid=" & URLEncode([Related Work Order]) & "&_fid_155=true" & "&apptoken=xxxxxxxxxxx" & "&rdr=" &URLEncode ( URLRoot() & "db/" & Dbid() &"?a=doredirect&z=" & Rurl())
    B.) Once I get the API_EditRecord formula correct, I'm not really sure how to structure my formula with the two API calls together and make it work.

    Any help, advice, or resources would be much appreciated!



    ------------------------------
    Thanks,
    Aleisha
    ------------------------------


  • 2.  RE: URL Formula Button w/ Two API Calls
    Best Answer

    Posted 05-19-2022 09:02
    You were really close The problem with the missing rid was that you had a leading _ underscore that did not belong.  Here is how I would write it to be all in one button.  I also strongly recommend that you make your formula as tidy and readable as possible like I have below.


    var bool ShowButton = Contains([Quote Status], "Approved by PM");

    var text Dispatch =
    URLRoot() & "db/" & [_DBID_STATUS_HISTORY]
    & "?a=API_AddRecord"
    & "&_fid_16=" & URLEncode ([Record ID#])
    & "&_fid_10=Subcontractor Dispatched"
    & "&_fid_11=Subcontractor Quote Status"
    & "&_fid_9=" & URLEncode(User())
    & "&apptoken=xxxxxxxxxxxxx";

    var text UpdateWorkOrder=
    URLRoot() & "db/" & [_DBID_WORK_ORDERS]
    & "?a=API_EditRecord"
    & "&rid=" & URLEncode([Related Work Order])
    & "&_fid_155=true"
    & "&apptoken=xxxxxxxxxxx";

    var text RefreshPage = URLRoot() & "db/" & Dbid() & "?a=doredirect&z=" & Rurl();

    // the this is the syntax to nest three successive API calls, but I set that also to be a formula variable.

    var text DoIt=
    $Dispatch
    & "&rdr=" & URLEncode($UpdateWorkOrder)
    & URLEncode("&rdr=" & URLEncode($RefreshPage));

    IF($ShowButton, $DoIt)


    Feel free to post back if there are any syntax errors, but include a copy of the code.




    ------------------------------
    Mark Shnier (YQC)
    mark.shnier@gmail.com
    ------------------------------



  • 3.  RE: URL Formula Button w/ Two API Calls

    Posted 05-20-2022 12:38
    Mark,

    You are AMAZING! It works beautifully!

    Thank you so much!!!

    ------------------------------
    Aleisha Aldrich
    ------------------------------