Quantcast
Channel: VMware Communities : Discussion List - vRealize Orchestrator
Viewing all articles
Browse latest Browse all 6251

How to read Array of SQL:ActiveRecord

$
0
0

We're trying to write a script here to query a database that keeps inventory of our servers, and automatically increment the server name to the next available number in the chain.  We're able to query the database but the output looks to be encrypted as it's not readable.  I'm thinking I need to convert it somehow to make it useful.  Anyone know how I could do this?  I'm a bit new to javascript so this is all new to me. 

 

Here's the script we've got so far.

 

var preservername = resultVMName;

 

 

function zeroPad(num,count)

{

  var numZeropad = num + '';

  while(numZeropad.length < count) {

    numZeropad = "0" + numZeropad;

}

  return numZeropad;

}

 

 

 

 

var query = 'SELECT MAX(ServerName) FROM servers WHERE ServerName like "%'+preservername+'%" limit 1';

System.log("Executing query" + query + "on database" + database.name);

resultRecordsOut = database.readCustomQuery(query);

System.log(resultRecordsOut[0]);

  var maxserver = resultRecordsOut[0].toString();

  System.log("This is the maxserver value" + maxserver);

    var prenumber = maxserver.substring(0,10);

    var numbers = parseInt(maxserver.substring(10,13));

    var newnumbers = zeroPad(numbers + 1, 2);

    var newname = prenumber + newnumbers;

 

 

System.log(newname);


Viewing all articles
Browse latest Browse all 6251

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>