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

Convert strings to Array (Composite Type)

$
0
0

I'm trying to create a Composite Type array within vCO for the purpose of passing data via the Guest Script Manager package.  I'm using the Guest Script manager to run a PowerShell script that will deploy the 1st domain controller in a new forest.  As of right now I only have 2 customized variables within the script; "$aminPassword" & "$domainName". If I was executing everything directly from vCO I'd have no issue because I could manually select the variables to replace when running the "Run Script in VM Guest" workflow.  Since the process will be initiated from vRA, I have to go through the painstaking process of creating a wrapper.

 

The workflow within the Guest Script Manager package where this logic is located is called "Run Script in VM Guest".  Within that workflow, there's a scriptable task called "Update Script"  That object has 2 inputs: vcoPath (type:String, attribute) who's value is the path where script is stored on vCO server, and scriptVariables (type: Composite Type(StringtoReplace:string,ReplacingString;string):scriptVariables).  The latter variable would normally be populated during the manual invocation of the workflow when the requester selects the script that they want to have ran.  Since I'm using vRA for the requesting, I have to script the population of the variable based upon string inputs.

 

The code for the Update Script scriptable task is:

 

var scriptFile = new FileReader(vcoPath);

 

scriptFile.open();

var script = scriptFile.readAll();

 

for each (var scriptVariable in scriptVariables) {

    System.log("Replacing variable " + scriptVariable.get("stringToReplace") + " with value " + scriptVariable.get("replacingString"));

    var search = escapeRegExp(scriptVariable.get("stringToReplace"));

    script = script.replace(new RegExp(search, "g"),scriptVariable.get("replacingString"));

}

 

//Saving unique file

System.log("Saving script " + vcoPath + " with content : \n" + script);

var fileWriter = new FileWriter(vcoPath);

fileWriter.open();

fileWriter.clean();

fileWriter.write(script);

fileWriter.close();

 

function escapeRegExp(str) {

  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");

}

 

 

 

I found the following script online to build the Composite Type array, but it doesn't seem to be working:

 

scriptVariables = new Array();

var jsObj = { name: "$domainName", value: domainName};

scriptVariables.push(jsObj);

var jsObj1 = { name: "$securePassword", value: somepassword};

scriptVariables.push(jsObj1);

 

In my solution, $domainName and $securePassword are the variables that are being replaced with the values of the vCO WF variables domainName and somePassword.

 

The error that I'm getting occurs on the "Update Script" scriptable task stating:

[2015-01-01 03:31:16.420] [I] Replacing variable null with value null

[2015-01-01 03:31:16.420] [I] TypeError: Cannot call method "replace" of null (Workflow:Wrapper Run script in VM guest / Update script (item29)#13)

 

I put a breakpoint on the scriptable task which holds the code to create the Composite Type array and saw that in fact it was creating an array consisting of 2 columns and 2 rows, but that it was empty.

 

I've been wracking my brain on this one for a while now and have only found a couple of posts on the web that have been only remotely helpful which brings me finally to my question:  Does anyone know how to resolve this?

 

v/r

 

Jeremy


Viewing all articles
Browse latest Browse all 6251

Trending Articles



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