Hi All,
I have a simple action with a SQL query where I get an array as result and which I use in a couple of workflow.
What I need now is also an action with a SQL query but as result is a string needed which I can define as "Default value" in the workflow presentation.
Here is the action which I have already with a result of Array/string
//database is input of Type SQL:Database
// table is input of Type SQL table
var currentUsersVMs = new Array();
//get the displayName of the workflow starter
try {
var jdbcConnection = new JDBCConnection();
var connection = jdbcConnection.getConnection(database.connectionURL, database.username, database.password);
System.debug("...connection successful");
var selectStatement = connection.createStatement();
//adjust with your column names to get a string like
//SELECT "Server Name" FROM "yourTable" WHERE "user" = "Karl Mustermann"
var selectString = "select SRV_Name from dbo.VC_Info_All where POWERSTATE = 'On' ORDER BY SRV_NAME";
System.debug("Executing query: " + selectString);
var resultSet = selectStatement.executeQuery(selectString);
// depending if you expect users with no VMs
//if (!resultSet) throw "No rows found in table '" + table.name + "'";
while (resultSet.next()) {
//resultSet columns start a 1!
currentUsersVMs.push(resultSet.getStringAt(1));
}
} catch (exception) {
throw "Error reading from database: " + exception;
} finally {
try { if (resultSet != null) resultSet.close(); } catch (e) {};
try { if (selectStatement != null) selectStatement.close(); } catch (e) {};
try { if (connection != null) connection.close(); } catch (e) {};
}
System.debug("VMs for current User: " + currentUsersVMs);
//for action:
return currentUsersVMs;