Forum Discussion

AshleyAshley1's avatar
AshleyAshley1
Qrew Trainee
7 years ago

Open record in another form and change the value of a field

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

6 Replies

  • 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.
    • QuickBaseCoachD's avatar
      QuickBaseCoachD
      Qrew Captain
      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.


       
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      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.
  • 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.