Skip to main content

logoCorrectSize.png

Workday Adaptive Planning Knowledge Center

Import Structure

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



function createPricesTable(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 = ai.https.request(url, method, body, headers);
    var parsed = JSON.parse(response.getBody());
    var result = parsed.results[0];
    var location = result.geometry.location;
    return [location.lat, location.lng];
}
  • Was this article helpful?