Forum Discussion

_anomDiebolt_'s avatar
_anomDiebolt_
Qrew Elite
7 years ago

Catamorphism Fields

I wanted to show you a new demo I put together that "summarizes" text fields in child records to the parent record that uses the new 3Q&S technique. After I show you the demo I will generalize what the technique can do and relate it to the title of this thread.

I haven't seen the new "combine text option for summary fields" yet but what I will show you blows the doors off this point feature in terms of what it can accomplish by "summarizing" or "aggregating" data in child fields to the parent record. 

Using the same data in the demo mentioned in this post:

Formulas and Reports
https://community.quickbase.com/quickbase/topics/formulas-and-reports
 
Programs ~ List All
https://haversineconsulting.quickbase.com/db/bn8if57nu?a=td

I convert the multi-select field to child records as demonstrated here:


Programs ~ View Record 1
https://haversineconsulting.quickbase.com/db/bn8kwquqq?a=dr&rid=1

The field [Equity Focus Areas] in the parent table is a Rich Text Formula field written in the style of the 3Q&S technique and has this definition:

"<img " &
"data-rid='" & [Record ID#] & "' " &
"src onerror='

(async () => {
  var dbid = 'bn8kwp9zq';
  var dbidPrograms = 'bn8kwquqq';
  var dbidEquityFocusAreas = 'bn8kwtf5y';
  var apptoken = 'c8ewpu4n734z94w2zqwdiu8s8n';
  $.ajaxSetup({data: {apptoken}});

  var fidRelatedPrograms = '7';
  var fidEquityFocusArea = '6';
  var tagEquityFocusArea = 'equity_focus_area';
  var rid = this.dataset.rid;
  let xml = await jqajax(
    $.get(dbidEquityFocusAreas, {
      act: 'API_DoQuery',
      query: '{${fidRelatedPrograms}.EX.${rid}}',
      clist: fidEquityFocusArea 
    })
  );  
  var markup = $('record', xml).map(function (index, record) {
    return $(tagEquityFocusArea, record).text();
  }).get()
  .join(', ');
  this.outerHTML = markup;
  // helper function
  async function jqajax(jqpromise) {
    return Promise.resolve(jqpromise);
  }
})();
'>"

This formula is self-contained and requires no setup such as is needed with other script injection techniques. You can modify the parameters and immediately use it in your application.

Additionally, you can modify the formula so that it styles the aggregated text into pills or bubbles


or performs additional transformations (such as hyperlinking) on the child fields prior to being inserted into the parent cell. There really is no limit to how you can process the child records into the parent record "summary" or "aggregate" field.

And the generality does not stop there. All of the aggregation functions hinted at in this screenshot can be accomplished with simple extensions to the above script:



Now lets relate this "aggregation" or "summary" feature to the title of this post "Catamorphism Fields".

Catamorphism
is just a super abstract concept in Mathematics that means to take a list of items and produce a single result. Programmers might call this process "fold" or "reduce" and layman might call this "summarize" or "aggregate". 

It is great that QuickBase has introduced text summary fields but occasionally you  are going to need other aggregation features that can easily be created using the 3Q&S technique.



Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=705
  • I'm attempting to use this technique to generate an html table (with child records, works great in QB) that I want to send with email. When I send the email, it sends the actual 3Q&S code and not the child records that it "catamorphized." Is there a way I can use that catamorphism data outside of QB?
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      QuickBase Formulas are evaluated on the QuickBase server and their calculated values are saved (probably through some type of caching strategy) on the server. These 3Q&S fields are script that "evaluate" client-side (ie in the browser) and the "evaluation value" is not saved on the server. Rather the "evaluation value" that  3Q&S calculates is merely displayed on the page or used to modify the behavior or appearance of the page in some way. If you wanted to save the value a 3Q&S calculate you have to make a supplemental API_EditRecord call such as this:
        let xml2 = await jqajax(
          $(dbidTable, {
            act: 'API_EditRecord',
            rid: rid,
            _fid_100: markup
          })
        );
      However, you appear to be calculating markup which includes a <table>. QuickBase will not allow you to store this type of content as it contains prohibited tags.

      If you want to send email, you can use the native method a=UserWin to send the email to a user by mimicking this native interface:



      The received email will look like this:



      The supplemental code to do this will look something like this:
        let html = await jqajax(
          $('main', {
            a: 'UserWin',
            uids: '51084879.bdbt',
            message: message,
            send: 'Send'
          })
        );
    • ParkerSmith's avatar
      ParkerSmith
      Qrew Trainee
      Thanks Dan, with this first snippet - where would you place it in relation to the initial "Equity Focus Area" example?

        let xml2 = await jqajax(
          $(dbidTable, {
            act: 'API_EditRecord',
            rid: rid,
            _fid_100: markup
          })
        );