Absent Member.. AntsInPants Absent Member..
Absent Member..
200 views

Parsing single line output into variables?

Jump to solution

Hi,

 

I have a VCenter advanced search operation that returns multiple values pipe-delimited values in a single result. The result includes both key=value, for example: "summary.config.numVirtualDisks:1". I would like to insert value 1 into a new output called 'numVirtualDisks' or 'summary.config.numVirtualDisks'.

I know how to iterate through the list of values, but I don't know how to achieve the above.

 

I tried to do a scriptlet, but can't get the this part working:

from scriptlet example: scriptletContext.put("LocalVariable","LocalValue");

my attempt: 

scriptletContext.put(mykey, myvalue);

 

any tips?

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: Parsing single line output into variables?

Jump to solution

So you can do this two ways; either with a loop of OO objects or in a scriplet filter on a result.

 

Using objects build an iteration loop with the following objects: List Iterator, Set Flow Variable. The list iterator will use the pipe as a separator and the results will split the name/value based on your separator for that (: or =). Set Flow Variable will then take the name/value as inputs.

 

Alternatively as a scriptlet:

 

var ArrValues;
var strName;
var strValue;

try {
	arrValues = scriptletInput.split("|");
	for(var i = 0; i < arrValues.length; i++) {
		strName = arrValues[i].substr(0, arrValues[i].indexOf(":"));
		strName = strName.substr(strName.lastIndexOf(".") + 1); // Remove this line if you want the whole config name
		strValue = arrValues[i].substr(arrValues[i].indexOf(":") + 1);
		scriptletContext.put(strName, strValue);
	}
	scriptletResult = "Successfully parsed all values into local variables.";
} catch(e) {
	scriptletResult = e;
}

 Hope this helps.

0 Likes
3 Replies
Highlighted
Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: Parsing single line output into variables?

Jump to solution

So you can do this two ways; either with a loop of OO objects or in a scriplet filter on a result.

 

Using objects build an iteration loop with the following objects: List Iterator, Set Flow Variable. The list iterator will use the pipe as a separator and the results will split the name/value based on your separator for that (: or =). Set Flow Variable will then take the name/value as inputs.

 

Alternatively as a scriptlet:

 

var ArrValues;
var strName;
var strValue;

try {
	arrValues = scriptletInput.split("|");
	for(var i = 0; i < arrValues.length; i++) {
		strName = arrValues[i].substr(0, arrValues[i].indexOf(":"));
		strName = strName.substr(strName.lastIndexOf(".") + 1); // Remove this line if you want the whole config name
		strValue = arrValues[i].substr(arrValues[i].indexOf(":") + 1);
		scriptletContext.put(strName, strValue);
	}
	scriptletResult = "Successfully parsed all values into local variables.";
} catch(e) {
	scriptletResult = e;
}

 Hope this helps.

0 Likes
Absent Member.. AntsInPants Absent Member..
Absent Member..

Re: Parsing single line output into variables?

Jump to solution
Thanks Steve! Much appreciated.
0 Likes
Absent Member.. AntsInPants Absent Member..
Absent Member..

Re: Parsing single line output into variables?

Jump to solution

We modified it a bit, also the split has to be escaped for pipe.

 

var arrValues;
var strName;
var strValue;
var myFullData = scriptletContext.getLocal("filteredReturn"); 

try {
	arrValues = myFullData.split("\\|");
	for(var i = 0; i < arrValues.length; i++) {
		var key_value = arrValues[i].split(":",2);
		strName = key_value[0].substr(key_value[0].lastIndexOf(".") + 1);
		scriptletContext.put(strName,key_value[1]);
		
	}
	scriptletResult = "Successfully parsed all values into local variables.";
} catch(e) {
	scriptletResult = e;
}
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.