ai.dataSource
The data source contains settings and tables.
Functions
Method | Parameters | Returns | Description |
|---|---|---|---|
getTables() | Array<ai.dataSource.table> | Returns a list of imported tables. | |
getTable( tableId ) | tableId : String Remote Id of the table | ai.dataSource.table | Returns the table with requested table id. Returns null if no table is found. |
getSettings() | Array<ai.dataSource.setting> | Returns all flexible settings. | |
getSetting( displayName ) | displayName : String Name of the setting | ai.dataSource.setting | Returns a flexible setting by its display name |
- Example
- function previewData(context) { var dataSource = context.getDataSource(); var allTablesInThisDataSource = dataSource.getTables(); //Navigate to Designer Settings tab, drag and drop a Static Integer parameter from the Settings Component //Setting Name: Custom Integer and Value: 100 var getSetting=dataSource.getSetting("Custom Integer" ); ai.log.logInfo(getSetting.getValue()); //100 }
ai.dataSource.table
Method | Parameters | Returns | Description |
|---|---|---|---|
getColumnByDisplayName( name ) | name : String Display name of the column | ai.dataSource.column | Finds a column by its display name. Returns null if no column found. |
getColumnById( id ) | id : String Remote Id of the column | ai.dataSource.column | Finds a column by its remote Id. Returns null if no column found. |
getColumns() | Array<ai.dataSource.column> | Returns all child columns that have been enabled for data import. | |
getDisplayName() | String | Returns the display name of the table. | |
getId() | String | Returns the remote Id of this table, or display name if no remote Id was specified. | |
getLastImported() | String | Returns a string identifying when the table was last imported. | |
getRelationships() | Array<ai.dataSource.relationship> | Returns all relationships where this table is the primary table of the relationship. | |
getRequiredParameters() | Array<ai.dataSource.table.requiredParameter> | Returns all table required parameters and their parameter values. | |
getRequiredParameter( id ) | id : String Remote Id of the required parameter as defined during Import Structure | ai.dataSource.table.requiredParameter | Returns a table required parameter by its remote Id. |
- Example
- //Consider a sample data source dataSample = { rows: [ {"Value": 10, "Measure": "", "Test": "No Space", "Effective Date": "2018-11-01"}, {"Value": 20, "Measure": " ", "Test": "One Space", "Effective Date": "2018-11-01"}, {"Value": 30, "Measure": " ", "Test": "Two Spaces", "Effective Date": "2018-11-01"}, {"Value": 40, "Measure": " ", "Test": "Three Spaces", "Effective Date": "2018-11-01"}, {"Value": 50, "Measure": "1 ", "Test": "Aus" + '\\-' + "tin" + '\\-', "Effective Date": "2018-11-01"}, {"Value": 10, "Measure": "2 ", "Test": "Austin", "Effective Date": "2018-12-01"}, {"Value": 20, "Measure": "3 ", "Test": "Austin", "Effective Date": "2018-12-01"}, {"Value": 30, "Measure": "4 ", "Test": "Austin", "Effective Date": "2018-12-01"}, {"Value": 40, "Measure": "5 ", "Test": "Austin", "Effective Date": "2018-12-01"} ] }; ExternalMetadataDefinition = { Tables : [ { name : "dataSample", displayName : "Sample", id:"dataSample", parameterId:"sampleParameter", columns : [ {name : "Value", displayName : "Value", type: "float", includeByDefault : true, }, {name : "Measure", displayName : "Measure", type: "text", includeByDefault : true}, {name : "Test", displayName : "Test", type: "text", includeByDefault : true}, {name : "Effective Date", displayName : "Date", type : "datetime", includeByDefault : true} ] } ] }; //Create a table structure function importStructure(context) { var addColumn = function(table, column, order) { var recordColumn = table.addColumn(column.name); recordColumn.setDisplayName(column.displayName); switch (column.type) { case "text": recordColumn.setTextColumnType(column.length); break; case "int": recordColumn.setIntegerColumnType(); break; case "float": recordColumn.setFloatColumnType(); break; case "boolean": recordColumn.setBooleanColumnType(); break; case "datetime": recordColumn.setDateTimeColumnType(); break; default: recordColumn.setTextColumnType(200); break; } recordColumn.setDisplayOrder(order); recordColumn.setIncludeByDefault(column.includeByDefault || false); recordColumn.setIncludeInKey(column.includeInKey || false); recordColumn.setMandatoryForImports(column.mandatoryForImport || false); recordColumn.setRemoteColumnType(column.remoteColumnType || "String"); }; var builder = context.getStructureBuilder(); var dataSource=context.getDataSource(); for (var i = 0; i < ExternalMetadataDefinition.Tables.length; i++) { var externalTable = ExternalMetadataDefinition.Tables[i]; var table = builder.addTable(externalTable.name); table.setDisplayName(externalTable.displayName); for (var j = 0; j < externalTable.columns.length; j++) { addColumn(table, externalTable.columns[j], j + 1); } } } //Examples for ai.datasource.table function importData(context){ var dataSource = context.getDataSource(); var alltablesinds=dataSource.getTables(); var rowset=context.getRowset(); //Example: getTableId; var tableId = rowset.getTableId(); ////dataSample var table= dataSource.getTable( tableId ); //Example: getDisplayName var dname=table.getDisplayName(); //Sample ai.log.logInfo("Table Display Name",dname); //Example: getLastImported var lastImported=table.getLastImported(); ai.log.logInfo("Last Imported:",lastImported); //Last Imported 10/23/2020 01:12:59 //Example: getId ai.log.logInfo("Table id",table.getId()) //dataSample }
ai.dataSource.table.column
Method | Parameters | Returns | Description |
|---|---|---|---|
getColumnType() | String | Returns the column type. Value is either 'DateTimeColumn', 'IntegerColumn', 'FloatColumn', 'BooleanColumn' or 'TextColumn'. | |
getDisplayName() | String | Returns the columns' display name. | |
getDisplayOrder() | String | Returns the columns' display order. | |
getId() | String | Returns the columns remote Id, or display name is no remote Id was specified. | |
getIncludeByDefault() | Boolean | Returns true if the column is included in the data import. | |
getIncludeInKey() | Boolean | Returns true if the column is part of the table key. Key columns do not allow null values. | |
getLength() | Integer | Note: Only for TextColumns. Returns the max length of values held in a TextColumn. | |
getMandatoryForImports() | True | Returns true if the column is required to be part of the data import. | |
getNonFilterable() | True | Returns true if the column cannot be used as part of a SQL filter (WHERE statement). | |
getRemoteColumnType() | String | Returns the columns' remote column type as defined in the import structure script. |
- Example
- //Consider a sample JSON data set dataSample = { rows: [ {"Value": 10, "Measure": "", "Test": "No Space", "Effective Date": "2018-11-01"}, {"Value": 20, "Measure": " ", "Test": "One Space", "Effective Date": "2018-11-01"}, {"Value": 30, "Measure": " ", "Test": "Two Spaces", "Effective Date": "2018-11-01"}, {"Value": 40, "Measure": " ", "Test": "Three Spaces", "Effective Date": "2018-11-01"}, {"Value": 50, "Measure": "1 ", "Test": "Aus" + '\\-' + "tin" + '\\-', "Effective Date": "2018-11-01"}, {"Value": 10, "Measure": "2 ", "Test": "Austin", "Effective Date": "2018-12-01"}, {"Value": 20, "Measure": "3 ", "Test": "Austin", "Effective Date": "2018-12-01"}, {"Value": 30, "Measure": "4 ", "Test": "Austin", "Effective Date": "2018-12-01"}, {"Value": 40, "Measure": "5 ", "Test": "Austin", "Effective Date": "2018-12-01"} ] }; ExternalMetadataDefinition = { Tables : [ { name : "dataSample", displayName : "Sample", id:"dataSample", parameterId:"2018-01-01", columns : [ {name : "Value", displayName : "Value", type: "float", includeByDefault : true, }, {name : "Measure", displayName : "Measure", type: "text", includeByDefault : true}, {name : "Test", displayName : "Test", type: "text", includeByDefault : true}, {name : "Effective Date", displayName : "Date", type : "datetime", includeByDefault : true} ] } ] }; function testConnection(context) { return true; } //Create a table structure function importStructure(context) { var addColumn = function(table, column, order) { var recordColumn = table.addColumn(column.name); recordColumn.setDisplayName(column.displayName); switch (column.type) { case "text": recordColumn.setTextColumnType(column.length); break; case "int": recordColumn.setIntegerColumnType(); break; case "float": recordColumn.setFloatColumnType(); break; case "boolean": recordColumn.setBooleanColumnType(); break; case "datetime": recordColumn.setDateTimeColumnType(); break; default: recordColumn.setTextColumnType(200); break; } recordColumn.setDisplayOrder(order); recordColumn.setIncludeByDefault(column.includeByDefault || false); recordColumn.setIncludeInKey(column.includeInKey || false); recordColumn.setMandatoryForImports(column.mandatoryForImport || false); recordColumn.setRemoteColumnType(column.remoteColumnType || "String"); }; var builder = context.getStructureBuilder(); var dataSource=context.getDataSource(); for (var i = 0; i < ExternalMetadataDefinition.Tables.length; i++) { var externalTable = ExternalMetadataDefinition.Tables[i]; var table = builder.addTable(externalTable.name); table.setDisplayName(externalTable.displayName); for (var j = 0; j < externalTable.columns.length; j++) { addColumn(table, externalTable.columns[j], j + 1); } } } //Examples for ai.datasource.table.column function importData(context) { var columnArray = rowset.getColumns(); var colIds=[]; var colDisplayNames=[]; var colTypes=[]; var colDisplayOrder=[]; var colIncludeByDefault=[]; var colLength=[]; for (var k = 0; k < columnArray.length; k++) { //Example:getColumnType colTypes.push(columnArray[k].getDisplayName().toString()+":"+columnArray[k].getColumnType().toString()); //Example:getDisplayName colDisplayNames.push(columnArray[k].getDisplayName().toString()); //Example:getDisplayOrder colDisplayOrder.push(columnArray[k].getDisplayName().toString()+":"+columnArray[k].getDisplayOrder().toString()); //Example:getId colIds.push(columnArray[k].getId().toString()); //Example:getIncludeByDefault colIncludeByDefault.push(columnArray[k].getDisplayName().toString()+":"+columnArray[k].getIncludeByDefault().toString()); //Example:getLength if(columnArray[k].getColumnType()==="TextColumn") { colLength.push(columnArray[k].getDisplayName().toString()+":"+columnArray[k].getLength()); } } ai.log.logInfo("Column Ids are "+colIds); //Column Ids are Effective Date,Value,Measure,Test ai.log.logInfo("Column Display names are "+colDisplayNames); //Column Display names are Date,Value,Measure,Test ai.log.logInfo("Column Types are "+colTypes); //Column Types are Date: DateTimeColumn, Value:FloatColumn, Measure:TextColumn,Test:TextColumn ai.log.logInfo("Column Display Order: "+colDisplayOrder); //Column Display Order: Date:4,Value:1,Measure:2,Test:3 ai.log.logInfo("Column Included by Default:"+colIncludeByDefault); //Column Included by Default:Date:true,Value:true,Measure:true,Test:true ai.log.logInfo("Length - "+colLength); //Length - Measure:200,Test:200 }
ai.dataSource.table.relationship
- Functions
- MethodParametersReturnsDescriptiongetJoinExpression()StringReturns the relationships' expression storage SQL e.g. 'P.Column123 = R.Column321'.getJoinType()IntReturns the relationships' type of join. Values are either 0 (Inner), 1 (LeftOuter) or 2 (RightOuter).getDisplayName()StringReturns the relationships' display name.getRelatedTableId()StringReturns the remote Id of the relationships' related table, or its display name is no remote Id was specified.getRelatedTableName()StringReturns the display name of the relationships' related table.
ai.dataSource.setting
Flexible settings are child items of a Custom Cloud Data Source. Settings can be static in that a value is configured, or they can be parameterized in that at script runtime, users are prompted to enter in a value for the setting. Examples of setting usage are urls, usernames, passwords, date ranges or dimensions that a script can access.
- Functions
- MethodParametersReturnsDescriptiongetDisplayName()StringReturns the settings' display name.getValue()MixedReturns the value of the setting's parameter. Value may be a primitive type or complex object - see Value Types below.isBoolean()BooleanReturns true if the setting type is Boolean.isDimension()BooleanReturns true if the setting type is Dimension.isInteger()BooleanReturns true if the setting type is Integer.isPassword()BooleanReturns true if the setting type is Password.isPeriodRange()BooleanReturns true if the setting type is PeriodRange.isText()BooleanReturns true if the setting type is Text.Example//Navigate to Designer Settings tab and drag an Integer Static parameter from the Settings Component pane //Name the setting Custom Integer and set the value to 100 var dataSource= context.getDataSource(); var setting=dataSource.getSetting("Custom Integer" ); //Example: getDisplayName var name = setting.getDisplayName(); //Custom Integer //Example: getValue var value = setting.getValue(); //100 // DataType checkup for the setting. if(setting.isInteger()){ ai.log.logInfo("Setting is of the type Integer"); //Setting is of the type Integer } //Check for other data types using setting.isPeriodRange(), setting.isInteger(), setting.isBoolean(), setting.isText(), setting.isPassword(), setting.isDimension();
- Value Types
- Each setting's getValue() function can return a primitive type or a complex object.Boolean Settings :getValue() returns the value as a Boolean.Text Settings :getValue() returns the value as a String.Integer Settings :getValue() returns the value as an Integer.Password Settings:getValue() returns the value as a String.Period Range Settings:getValue() returns the value as a complex object. This object is defined as such:MethodParametersReturnsDescriptiongetFromPeriod()StringReturns a string defining the internal representation of resolvedAdaptive PlanningFrom Period that can be used to pass to the ai.calendar method calls. E.g. "3152|5201611100000"getToPeriod()StringReturns a string defining the internal representation of resolvedAdaptive PlanningTo Period that can be used to pass to the ai.calendar method calls. E.g. "3152|5201611100000"getFromPeriodStartDateTime()StringReturns a datetime string representation of the From Period start datetime, expressed in local time. E.g. "2016-01-01T00:00:00+10:00"getFromPeriodEndDateTime()StringReturns a datetime string representation of the From Period end datetime, expressed in local time. E.g. "2016-02-01T00:00:00+10:00"getToPeriodStartDateTime()StringReturns a datetime string representation of the To Period start datetime, expressed in local time. E.g. "2016-06-01T00:00:00+10:00"getToPeriodEndDateTime()StringReturns a datetime string representation of the To Period end datetime, expressed in local time. E.g. "2016-07-01T00:00:00+10:00"
- Example
- function importData(context) { var dataSource = context.getDataSource(); //getFromPeriod var getFromPeriod=dataSource.getSetting("Period Range").getValue().getFromPeriod(); //getToPeriod var getToPeriod=dataSource.getSetting("Period Range").getValue().getToPeriod(); //getFromPeriodStartDateTime var getFromPeriodStartDateTime = dataSource.getSetting("Period Range").getValue().getFromPeriodStartDateTime().substring(0, 10); ai.log.logInfo("getFromPeriodStartDateTime"+getFromPeriodStartDateTime); //2017-12-01 //getFromPeriodEndDateTime var getFromPeriodEndDateTime = dataSource.getSetting("Period Range").getValue().getFromPeriodEndDateTime().substring(0, 10); ai.log.logInfo("getFromPeriodEndDateTime"+getFromPeriodEndDateTime); //2017-12-31 //getToPeriodStartDateTime var getToPeriodStartDateTime = dataSource.getSetting("Period Range").getValue().getToPeriodEndDateTime().substring(0, 10); ai.log.logInfo("getToPeriodStartDateTime"+getToPeriodStartDateTime); //2018-01-01 //getToPeriodEndDateTime var getToPeriodEndDateTime = dataSource.getSetting("Period Range").getValue().getToPeriodEndDateTime().substring(0, 10); ai.log.logInfo("getToPeriodEndDateTime"+getToPeriodEndDateTime); //2018-01-30 }
Dimension Settings
Dimension Settings
getValue() returns the value as a complex object. This object is defined as such:
Method | Parameters | Returns | Description |
|---|---|---|---|
getDimensionName() | String | Returns the name of the Dimension defined in the value. | |
getValueName() | Mixed | Returns the name of the Dimension Member defined in the value. |
- Example
- //Navigate to Designer Settings tab and drag a Static Dimension parameter from the Settings Component pane //Name the setting "Custom Dimension" and set a value from the Static Dimension Setting dropdown var setting=dataSource.getSetting("Custom Dimension" ); var value = setting.getValue(); //Example: getDisplayName var name = value.getDimensionName(); var settingValue=value.getValueName(); ai.log.logInfo("Dimension Settings Name: "+name+" and Dimension Settings Value: "+settingValue); //Dimension Settings Name: Level and Dimension Settings Value: Company B (40% owned)Example for Dimension Settings //Navigate to Designer Settings tab and drag a Static Dimension parameter from the Settings Component pane //Name the setting "Custom Dimension" and set a value from the Static Dimension Setting dropdown var setting=dataSource.getSetting("Custom Dimension" ); var value = setting.getValue(); //Example: getDisplayName var name = value.getDimensionName(); var settingValue=value.getValueName(); ai.log.logInfo("Dimension Settings Name: "+name+" and Dimension Settings Value: "+settingValue); //Dimension Settings Name: Level and Dimension Settings Value: Company B (40% owned)
ai.dataSource.table.requiredParameter
During script execution, valid Required Parameters prompt a user to provide values. These values are then accessible in scripts. Required Parameters can be created during importStructure.
During ImportData, only Required Parameters that have been configurable as setForDataImport(true) are accessible in the script.
- Functions
- MethodParametersReturnsDescriptiongetId()StringReturns the required parameter's remote Id.getValue()MixedReturns the value of the required parameter's parameter. Value may be a primitive type or complex object - see Value Types below.isBoolean()BooleanReturns true if the required parameter's type is Boolean.isDimension()BooleanReturns true if the required parameter's type is Dimension.isInteger()BooleanReturns true if the required parameter's type is Integer.isPassword()BooleanReturns true if the required parameter's type is Password.isPeriodRange()BooleanReturns true if the required parameter's type is PeriodRange.isText()BooleanReturns true if the required parameter's type is Text.
- Value Types
- Each required parameter's getValue() function can return a primitive type or a complex object.Boolean Required ParametersgetValue() returns the value as a Boolean.Text Required ParametersgetValue() returns the value as a String.Integer Required ParametersgetValue() returns the value as an Integer.Password Required ParametersgetValue() returns the value as a String.Period Range Required ParametersgetValue() returns the value as a complex object. This object is defined as such:MethodParametersReturnsDescriptiongetFromPeriod()StringReturns a string defining the resolvedAdaptive PlanningFrom Period. E.g. "Month y2016 M1"getToPeriod()StringReturns a string defining the resolvedAdaptive PlanningTo Period. E.g. "Month y2016 M1"getFromPeriodStartDateTime()StringReturns a datetime string representation of the From Period start datetime, expressed in local time. E.g. "2016-01-01T00:00:00+10:00"getFromPeriodEndDateTime()StringReturns a datetime string representation of the From Period end datetime, expressed in local time. E.g. "2016-02-01T00:00:00+10:00"getToPeriodStartDateTime()StringReturns a datetime string representation of the To Period start datetime, expressed in local time. E.g. "2016-06-01T00:00:00+10:00"getToPeriodEndDateTime()StringReturns a datetime string representation of the To Period end datetime, expressed in local time. E.g. "2016-07-01T00:00:00+10:00"
- Dimension Settings
- getValue() returns the value as a complex object. This object is defined as such:MethodParametersReturnsDescriptiongetDimensionName()StringReturns the name of the Dimension defined in the value.getValueName()MixedReturns the name of the Dimension Member defined in the value.