Clear a date field when a new drop-down selection is made

  • 0
  • 1
  • Question
  • Updated 11 months ago
  • Answered
Every department has a report to track incoming communication. On the report, I've created buttons to quickly track the communication process. When a new record is appears, the department clicks the 'Received' button which puts a timestamp into a time/date field. I have another button that is called 'Change Dept' so that the communication could be transferred to another department. However, I need the 'Time Received' field to clear so that the record arrives into the new department as if it is a new record. I have the following code to update the department, and need to know what I can add to it to clear the time date field (fid=10) at the same time:

URLRoot() & "db/" & Dbid() & "?a=er&dfid=11&rid=" 
& ToText([Record ID#])
Photo of Kelly

Kelly

  • 1,762 Points 1k badge 2x thumb

Posted 11 months ago

  • 0
  • 1
Photo of QuickBaseCoach App Dev./Training

QuickBaseCoach App Dev./Training, Champion

  • 51,486 Points 50k badge 2x thumb
Unfortunately there is no API to open a record in edit mode and pre-populate some fields.  That syntax above is not really an API.

So you would need to actually edit the record, and then open the record in edit mode.

The formula would be

var text URLONE = URLRoot() & "db/" & Dbid()
& "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_999=" // this puts nothing into that field, so it gets blanked out.
& "&apptoken= xxxxxxxxxx";

var text URLTWO = URLRoot() & "db/" & Dbid() & "?a=er&dfid=11&rid=" 
& ToText([Record ID#]);

$URLONE
& "&rdr=" & URLEncode($URLTWO)

Note that when the user clicks the button, the time stamp field will be cleared, regardless if they bail out while editing the record to change it to another department.  That is because the formula URL above will first do the edit to clear the time stamp and then open the record for manual editing.

Change the 999 to your actual Time stamp field ID, and the need for the application token depends on whether you have Application Tokens required for your app as an extra layer of security.  That requirement can be disabled ion Application Properties.
Photo of Kelly

Kelly

  • 1,762 Points 1k badge 2x thumb
Yeah, I figured it would be deleted, but the department changes are logged and time-stamped in another field, so I'm good with that. I just need the blank date in order to trigger the row colorization which lets the department know that it's an incoming request. It worked beautifully. Thank you!
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,572 Points 20k badge 2x thumb
Using script and the IOL technique you can easily implement a generic technique that will allow you to add custom parameters to the common record manipulation URLs. In particular you can add the desired functionality to initialize field value of the ?a=er URL. Here is a demo and screenshot showing editing the first record with and without the custom _fid_* URL parameters::



https://haversineconsulting.quickbase.com/db/bncssrtjv?a=er&rid=1



https://haversineconsulting.quickbase.com/db/bncssrtjv?a=er&rid=1&_fid_6=Mu&_fid_8=Eta

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

Notes:

(1) The code in the pastie is generic and can be used to implement this functionality for any table or set of fields.

(2) The IOL field is included only for ?a=er pages

(3) This technique  of adding custom properties and parsing them out in script to perform some useful action can be extended to many other use cases. For example you could easily arrange to pass the name of a code page with a parameter &script=myscript.js and within with the IOL module.js page just insert a generic $.getScript() to load the script passed in the URL.

Once I come up with a snappy name for this technique I will add it to my forthcoming QuickBase Swimlane Catalog (it's big and chocked full of goodies):

(Edited)
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,572 Points 20k badge 2x thumb
FWIW, I modified the code to do a destructuring assignment as indicated below::

(function(){
  var querystring=document.location.search;
  if(/a=er/i.test(querystring)) {
    var params = new URLSearchParams(location.search);
    for (var [fid, value] of params.entries()) {
      if (fid.indexOf("_fid_") == 0) {
        $("#" + fid).val(value);
      }
    }
  }
})();