Provide Records and Storage information in the live app

In the current version there is no way to display the number of records and Storage of an app in the live version. That is only possible in the Builder
In addition, it would be fine if we could defined the max number of records and Storage for each app :

Example :

App 1 : Max records : 5,000 / Storage : 500 Mb

App 2 : Max records : 10,000 / Storage : 2 GB

etc...

Sure. For example, i created a new object called "Usage"

And these are the fields in it:

Then i added a new Page:

The Edit Record link is important as we are going to use this to update the usage data.

After this you should create a new (blank) Usage record, via the Builder.

Then go back to the "Usage Data" Page in the Live App and go to the Edit record link, to retrieve the Record ID.

https://xyz.knack.com/your-app#usage-data/edit-usage/{RECORD ID}/  )

One last thing to do after this is to create the code in the JS console:

 

 

$(document).on('knack-record-create.any knack-record-delete.any', function(event, view) {

  let data = {
    field_162: Knack.app.attributes.counts.total_entries,
    field_163: Knack.app.attributes.counts.asset_size,
    field_164: Knack.app.attributes.account.plan_limits.records,
    field_165: Knack.app.attributes.account.plan_limits.storage
};
  let headers = {'Authorization': Knack.getUserToken(), 'X-Knack-Application-Id': 'YOUR-APP-ID', 'X-Knack-REST-API-Key': 'knack'};
  let api_url = "https://api.knack.com/v1/pages/scene_AAA/views/view_BBB/records/{RECORD ID}";

  $.ajax({
    url: api_url,
    type: "PUT",
    headers: headers,
    data: data,
    success: function(response) {  
      console.log("Usage updated!");
    }
  });

});

 

This code will fire every time a record is created or deleted in your app.

It will keep updating the one particular record in the "Usage" object, which you can then use anywhere, however you like.

 

Hope this helps.

 

Thank you Shrey but I a low code user :). How and where can I use these variable to get the information ?

and Knack.app.attributes.account.plan_limits.records & Knack.app.attributes.account.plan_limits.storage to retrieve the overall limits for your Knack account

Hey 398722061672, you could use the Knack.app.attributes.counts.total_entries  &  Knack.app.attributes.counts.asset_size  variables to retrieve the no. of records and the utilised storage, respectively, for your app.