Skip to main content
Skip table of contents

Advanced reports

See Add report for information on how to add a report. When 'Advanced' is selected, the following page will display, including a place to enter a code service name:

image-20240610-164900.png

A sample code service that could be used in an advanced report is provided below.

JS
function sample(req,resp){


   var reportObj = {
       columns: [{
           columnType: "text",
           field: "YOUR_FIELD",
           title: "YOUR FIELD"
       }, {
           columnType: "text",
           field: "YOUR_OTHER_FIELD",
           title: "YOUR OTHER FIELD"
       }],
       data: []
   };


   function getAllAssets() {
       var assetsCollection = ClearBladeAsync.Collection('assets');
       var query = ClearBladeAsync.Query();
       query.equalTo('type', 'YOUR_ASSET_TYPE');
       return assetsCollection.fetch(query).then(function (results) {
           return results.DATA;
       });
   }


   getAllAssets().then(function(allAssetDetails) {
       for (var x = 0; x < allAssetDetails.length; x++) {
           var row = {};
           //fields ex: id, label, custom_data, location
           row.YOUR_FIELD =allAssetDetails[x].YOUR_FIELD
           row.YOUR_OTHER_FIELD = allAssetDetail[x].YOUR_OTHER_FIELD
           reportObj.data.push(row);
       }
       resp.success(reportObj);
   }).catch(function (reason) {
       console.error('failed: ', reason);
       resp.error(reason);
   });
  
}

Further resources: Code services, Code services tutorial, ClearBlade async docs

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.