Application information for the end user : records/storage/tasks

Hello everyone… has anyone ever had to put the application information for the end user into a form: number of records/storage usage/number of active tasks

Any ideas on how to access this information in the builder and make it available to the end user?

Hi @W3Agro, here’s one way to grab that data. It uses the Knack application model to fetch record count and asset size, as well as looping through all objects to find which tasks are running. It then displays it in a Rich Text view on a particular page.

Requirements:

  • A page (scene_xx) containing a Rich Text view with HTML <div id="appSummary"></div>.

Code:
EDIT: Updated code to remove the need to call the API. Special thanks to @KnackPros for the optimisation!

$(document).on('knack-scene-render.scene_xx', function(event, scene) {

  const recordCount = Knack.app.attributes.counts.total_entries;
  const assetSize = Knack.app.attributes.counts.asset_size;
  let taskCount = 0;
    $.each(Knack.objects.models, function(objectName, object) {
      $.each(object.tasks.models, function (index, task) {
        if (task.attributes.run_status === "running") {
          taskCount += 1;
        }
      });
    });
    const appSummary = `Record Count: ${recordCount} <br /> Asset Size: ${assetSize} Bytes <br /> Active Task Count: ${taskCount}`
    $("#appSummary").append(appSummary);

});
4 Likes

Looks like something even I could implement :man_technologist:
This shouldn’t stretch my “copy & pasting skills” too much.
Looking forward to giving it a try.
Thank you for sharing @StephenChapman :+1:

1 Like

Thanks Carl!
Also noting that this can be used to fetch lots more metadata about an app if you know the application model well, with a bit of JS experience.
And also a reminder that Nir Tzur in this forum created this fantastic Knack Definitions app to get a good summary of that metadata too!

Thanks Stephen!!
It certainly helped us a lot in development.
You guys are great!! :sunglasses:

1 Like