Skip to main content
Adaptive Insights
Knowledge and Support - Adaptive Insights

Import Structure

function importStructure(context) {
   var builder = context.getStructureBuilder();
   var progressManager = context.getProgressManager();
   var progressIncrement = 100 / 2;
   createTable(builder);
   progressManager.setProgress(progressManager.getProgress() + progressIncrement);
   createTimesTable(builder);
   progressManager.setProgress(progressManager.getProgress() + progressIncrement);
}


function createTable(builder) {
   var tableId = 'prices';
   var tableDisplayName = 'Prices';
   var table = builder.addTable(tableId);
   table.setDisplayName(tableDisplayName);
   var i = 0;
   createColumn(table, "localized_display_name", "Localized Display Name", i++, false, "string");
   createColumn(table, "high_estimate", "High Estimate", i++, false, "number");
   createColumn(table, "minimum", "Minimum", i++, false, "number");
   createColumn(table, "duration", "Duration (seconds)", i++, false, "number");
   createColumn(table, "estimate", "Estimate", i++, false, "string");
   createColumn(table, "distance", "Distance (miles)", i++, false, "number");
   createColumn(table, "display_name", "Display Name", i++, false, "string");
   createColumn(table, "product_id", "Product Id", i++, false, "string");
   createColumn(table, "low_estimate", "Low Estimate", i++, false, "number");
   createColumn(table, "surge_multiplier", "Surge Multiplier", i++, false, "number");
   createColumn(table, "currency_code", "Currency Code", i++, false, "string");
}


function createTimesTable(builder) {
   var tableId = 'times';
   var tableDisplayName = 'Times';
   var table = builder.addTable(tableId);
   table.setDisplayName(tableDisplayName);
   var i = 0;
   createColumn(table, "localized_display_name", "Localized Display Name", i++, false, "string");
   createColumn(table, "estimate", "Estimate (seconds)", i++, false, "number");
   createColumn(table, "display_name", "Display Name", i++, false, "string");
   createColumn(table, "product_id", "Product Id", i++, false, "string");
}


function createColumn(table, columnId, columnDisplayName, displayOrder, mandatoryForImports, dataType) {
   var column = table.addColumn(columnId);
   column.setDisplayName(columnDisplayName);
   column.setDisplayOrder(displayOrder);
   column.setMandatoryForImports(mandatoryForImports);
   switch (dataType) {
       case "integer":
           column.setIntegerColumnType();
           break;
       case "string":
       case "base64_encoded":
           column.setTextColumnType(100);
           break;
       case "date":
           column.setDateTimeColumnType();
           break;
       case "datetime":
           column.setDateTimeColumnType();
           break;
       case "boolean":
           column.setBooleanColumnType();
           break;
       case "number":
       case "currency":
           column.setFloatColumnType();
           break;
       default:
           // unknown type
           ai.log.logInfo('Unable to create a column. Its type is unknown.', 'Column ' + columnId + ' could not be created because its data type was not known. Its data type was ' + dataType +
               '.');
           break;
   }
}


function convertAddressToGeoCode(address, key) {
   var url = 'https://maps.googleapis.com/maps/api.../json?address=' + encodeURI(address) + '&key=' + key;
   var method = 'GET';
   var headers = {
       'Content-Type': 'text/json'
   };
   var body = '';
   var response = JSON.parse(ai.https.request(url, method, body, headers).getBody());
   var long = response.results[0].geometry.location.lng;
   var lat = response.results[0].geometry.location.lat;
   return [lat, long];
}
  • Was this article helpful?