Discussions

 View Only
  • 1.  Open record in another form and change the value of a field

    Posted 09-28-2017 09:31
    Hi

    I'm trying to add a button which will open the same record in a different form but at the same time editing a field within that form.

    i have this so far which opens the record in the other form but what i cant figure out is how to add in the piece which will edit the checkbox field to true. The checkbox field id is 155.

    URLRoot() & "db/" & Dbid() & "?a=er&key="&[Record ID#]&"&dfid=11"

    Any guidance would be appreciated 

    Thanks


  • 2.  RE: Open record in another form and change the value of a field

    Posted 09-28-2017 12:48
    So you cannot actually populate a checkbox field when opening the record to edit.

    The only option would be to actually have that checkbox set to checked under the covers and then display the record in Edit mode.

    The subtle difference is that when the user clicks the button, that checkbox will be checked, regardless if they choose to back out of the edit process and not actually save the record.

    The code would be in two steps like this, using formula variables for each step.

    var Checkbox= URLRoot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
    & "&apptoken=xxxxxxx"
    & "&_fid_155=1;

    var Edit = URLRoot() & "db/" & Dbid() & "?a=er&key="&[Record ID#]&"&dfid=11";

    $Checkbox
    & "&rdr=" & URlEncode($Edit)


    If you have application tokens set to be required you will need to supply that line
    & "&apptoken=xxxxxxx"

    or else disable them on the Settings in App properties and then you don't need that line.


  • 3.  RE: Open record in another form and change the value of a field

    Posted 09-28-2017 13:18
    >So you cannot actually populate a checkbox field when opening the record to edit.

    It is worth noting that jotform allows you to do this through passing query string parameters:

    https://www.jotform.com/help/71-Prepopulating-Fields-to-Your-JotForm-via-URL-Parameters

    It would not be that hard to mimic this using the IOL technique.

    Curiously QuickBase does allow you to do this for new records:

    ?a=nwr&_fid_6=foo&_fid_7=bar



  • 4.  RE: Open record in another form and change the value of a field

    Posted 09-28-2017 13:31
    Re: "Curiously QuickBase does allow you to do this for new records:"

    It must be because there is an API for API_GenAddRecordForm (which must be what happens when the short form of a=nwr is used),  but there is no API for "API_EditRecordForm" - ie that does not exist as an API.


     


  • 5.  RE: Open record in another form and change the value of a field

    Posted 09-28-2017 13:43
    But this is easy to do with script and IOL:

    Here is a screenshot of me manually applying a three line script



    var urlParams = new URLSearchParams(window.location.search);
    _fid_6.value = urlParams.get('_fid_6');
    _fid_7.value = urlParams.get('_fid_7');

    So the IOL module.js code page would be this simple script:

    (function(){
      var querystring=document.location.search;
      if(/a=er/i.test(querystring)) {
        var urlParams = new URLSearchParams(window.location.search);
        _fid_6.value = urlParams.get('_fid_6');
        _fid_7.value = urlParams.get('_fid_7');
      }
    })();

    This is actually a perfect example of my JavaScript rant yesterday which was probably over most user's heads but is simple to understand in this instance.

    JavaScript keeps getting better every day. Now there is (1) a new object available named URLSearchParams that will allow you to manipulate the URL's query parameters and (2) the browser automatically creates globals for all element ids in the page (ie _fid_6 and _fid_7).

    You will not see URLSearchParams anywhere in QuickBase's code base but you will find various legacy code fragments that does the same thing. It isn't QuickBase's fault - every software company experiences this problem as the technology is changing too fast for even senior developers to keep up. Quite frankly I would be surprised if many QuickBase developers even know about these two particular features. Except that cute one - she seems like she knows her stuff.


  • 6.  RE: Open record in another form and change the value of a field

    Posted 09-28-2017 13:58
    Okay I just add this to the Pastie database:

    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=600

    It is worth noting two things:

    (1) I have two statements in my code that sort of do the same general thing (manipulate the query string) - one old school and one new school:

    var querystring=document.location.search;

    var urlParams = new URLSearchParams(window.location.search);

    This precisely how legacy code builds up. It happens to everyone. And no I am not going to change anything because this is throw away code.

    (2) Well we reached 600 pasties today. To celebrate I am going slack off for the rest of the month and binge watch Silicon Valley reruns while checking every episode with TvTropes (http://tvtropes.org/pmwiki/pmwiki.php/Series/SiliconValley">http://tvtropes.org/pmwiki/pmwiki.php/Series/SiliconValley">http://tvtropes.org/pmwiki/pmwiki.php/Series/SiliconValley).


  • 7.  RE: Open record in another form and change the value of a field

    Posted 09-28-2017 14:46
    I create a simple application:

    Edit Record With Field Override ~ Edit Record #1
    https://haversineconsulting.quickbase.com/db/bm5ep5eb7?a=er&rid=1

    You can tack on parameters to the URL that will set values for _fid_6 and/or _fid_7 immediately when the form opens.

    ?a=er&rid=1&_fid_6=Jane Doe&_fid_7=4/5/2018
    ?a=er&rid=1&_fid_6=John Doe&_fid_7=1/2/2019

    I modified the pastie slightly to not change the field unless a value is supplied in the URL:

    Pastie Database
    https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=600

    The example hardcoded processing of only these two fids but it would not be difficult to modify the script to process any supplied fid.

    FWIW, the reason QuickBase probably did not implement this feature on ?a=er (but they did on ?a=nwr) might be because you loose knowledge of what the old value of the field was so it is probably a safety thing.