Discussions

Expand all | Collapse all

API Edit call that also saves entered text and returns to edit mode at same spot in report

  • 1.  API Edit call that also saves entered text and returns to edit mode at same spot in report

    Posted 04-19-2019 22:00
    I have a Formula - URL / Formula - Rich Text (I've tried both) button that performs an API EditRecord which checks a box and records a single blank space in a text box (which is time-stamped, so it acts as a log).

    I want the user to be able to enter a comment in a separate multi-line text field, then click the button that performs the API Edit.  I want the end result to be that the user-entered comment is saved, the two edits are performed, and it returns the user to the form page, in edit mode, without losing their spot within the report (the Prev and Next buttons still appears in the top right).

    I've tried to implement this a few ways.  I have tried:

    var text Submit = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" & "&rid=" & [Record ID#] &
        "&apptoken=XXXXXXXXXXXXXXXX" &
        "&_fid_67= " &
        "&_fid_61=True";

    "<a class='Vibrant Danger'; onclick=$('#SaveAndKeepWorkingMenuOption').click(); href='" & $Submit &"'>Submit & Keep Working</a>"

    But that method does not preform the proper redirect. It just takes me to the XML result page.

    I have tried appending:

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

    But the problem with that is that the API Edit call and the text entered by the user seem to "fight" each other, and Quick Base throws up an error screen saying that you are trying to enter two pieces of data at the same time - which one do you want to save?

    I have also tried:

    URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" & "&rid=" & [Record ID#] &
        "&apptoken=XXXXXXXXXXXXXXXX" &
        "&_fid_67= " &
        "&_fid_61=True";
        "&rdr=" & URLEncode(URLRoot() & "db/" & Dbid() & "?a=er&rid=" & [Record ID#])

    This returns me to the edit screen but it loses my place in the report, and the Prev / Next buttons disappear.

    I have the Save and Keep Working button checked on the form, and I have the "Save parent record automatically when a child record is created" option checked in the Advanced Settings for the table.


  • 2.  RE: API Edit call that also saves entered text and returns to edit mode at same spot in report

    Posted 04-24-2019 13:10
    So to answer / cover 3 topics from above - 

    #tdf_81 would ideally be the your field - yes. Its the unique identifier in the HTML that calls at that particular element. 

    As for the syntax - to follow the method if you are still shooting for a button - you can't declare another variable outside of your js invocation - it has be inside because its not a part of Quick Base formula syntax - but actual JS. So what I copied above was close to what you need - updated based on your inclusions above

    var text submit = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" & "&rid=" & [Record ID#] &
        "&apptoken=XXXXXXXXXXXXXXXX" &
        "&_fid_67= " &
        "&_fid_61=True" & 
        "&_fid_81=";

    "javascript: {
    var input = $("#tdf_81")[0].innerHTML;
    $.get(' " & $submit & "' + input, function(data,success) { location.reload() } );
    }"

    In this case - when you start your javascript - step one is to grab the value from the page of field 81 using jQuery from inside of your actual JS. Step two - is to start your get, using your $submit Quick Base formula - but use it in a way that you can add the input from field 81. This is why the $.get looks like (I've added spacing to make it more clear 

    $.get( ' " & $submit & " ' + input, function...

    Inside your get you're putting a url - which at its core is just a string. So you start it with what you already have with your $submit - and then since your still in Javascript syntax - you do a + input to tack on the variable that you used to store the value of fid 81

    Hopefully that helps describe it a little better.

    As for using form rules - couldn't form rules take care of your spacing and checking the box? I'm not sure what the exact workflow is - but it seems like this button might be a bit much for what you're trying. Have you considered something like having a checkbox instead of a button - or dropdown to confirm? When that is checked or a value is entered - form rule fires to check your box and add a space to your log field. Then they would just save as normal. Same thing could be done with automations too 

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 3.  RE: API Edit call that also saves entered text and returns to edit mode at same spot in report

    Posted 04-24-2019 02:54
    So to toss out an idea as an addition to your middle solution using the $.get and reload() -  have you thought about just using jQuery to grab the value fo the text box thats being entered in and append that as part of the single $.get() edit call? 

    Put another way - instead of trying to save first to allow the user to input something and then do a secondary edit, when you start your JS - declare a simple variable and use jQuery to get the text value of you multi-line text box they typed in - and then append that onto your original editRecord call. Kind of like 

    var text Submit = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" & "&rid=" & [Record ID#] &
        "&apptoken=XXXXXXXXXXXXXXXX" &
        "&_fid_67= " &
        "&_fid_61=True" &
        "&_fid_62=";
    => Notice you include your text field in your submit call - but leave the value of your last field open ended

    "javascript: {
    var input = $("#tdf_17")[0].innerHTML;
    $.get(' " & $submit & "' + input)
    .."

    So you leave your submit function 'unfinished' until you can grab the value of the text value. You don't actually 'save' the record - you just make you editRecord call and reload so its only one thing happening and QB doesn't fight itself

    Just curious - is there a reason you can't have form rules or automations handle the logs themselves and let people save normally?

    Chayce Duncan | Technical Lead
    (720) 739-1406 | chayceduncan@quandarycg.com
    Quandary Knowledge Base


  • 4.  RE: API Edit call that also saves entered text and returns to edit mode at same spot in report

    Posted 04-25-2019 04:19
    Thanks! Unfortunately I couldn't get the javascript to work. The button would save the record (and the text in the comment box) but wasn't triggering the API call. It was essentially just functioning as a regular save button.


  • 5.  RE: API Edit call that also saves entered text and returns to edit mode at same spot in report

    Posted 04-24-2019 05:54
    Thanks! I should stress that my skills with javascript are limited to stuff I've copied from community posts here, so if you don't mind clarifying slightly how the script should look, that would be awesome.

    Something like this?

    var text Submit = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord" & "&rid=" & [Record ID#] &
        "&apptoken=XXXXXXXXXXXXXXXX" &
        "&_fid_67= " &
        "&_fid_61=True" & 
        "&_fid_81=";    

    var input = $("#tdf_81")[0].innerHTML;

    var text SubmitAction = "javascript:$.get('" & $Submit & $input &"',function(){location.reload(true);});void(0);";

    $SubmitAction

    I wasn't sure if the var input belongs inside the javascript or outside as a regular variable.  I'm also not sure what "#tdf_81" is calling but I'm assuming a specific field / my comment field?

    You're right - I could have a dynamic form rule to add a space to fid 67, but since I also need the checkbox to be checked, I figured I could put both those things into one API call. I'm sort of just trying to figure out how much I can cram into a single button and what the possibilities are.

    The workaround I've put in place in the meantime is two separate buttons. One that is a "save and keep working button" that stores the comment text, and then the next is the API call / reload button.  If one button can do both things, that would be awesome.


  • 6.  RE: API Edit call that also saves entered text and returns to edit mode at same spot in report

    Posted 09-15-2021 11:52
    Edited by Daniel Johnson 09-15-2021 11:52
    Chayce, have you implemented a button like this since this post? I'm trying to do the same thing, add the return to location functionality to this button: https://resources.quickbase.com/db/bq8meiyhh?a=dr&key=-1

    That button is currently working for me as is, expect the code page claims it's supposed to be in a Formula - URL field, when in fact it's supposed to be a Formula - Rich Text field. Shoutout to Lisa Sell for figuring that out!

    Any guidance would be greatly appreciated.

    ------------------------------
    Daniel Johnson
    ------------------------------