Consistent SSJS Multi-Value Formatting

/**
 * @author Eric McCormick
 * twitter: @edm00se
 * src: https://edm00se.io/xpages/consistent-multivalue-formatting/
 * 
 * @param java.util.Object to examine
 * @return java.util.Vector of values from originating Object
 **/
function getValueAsVector(obj){
	switch(typeof obj){
		case "java.util.Vector": //it's already a Vector, just return it
			return obj;
			break;
		case "java.util.ArrayList": //it's an ArrayList, return it as a Vector
		case "Array": //it's an Array prototype, return it as a Vector
			var x:java.util.Vector = new java.util.Vector();
			var s = obj.size()||obj.length;
			for(var i=0; i<s; i++){
				x.add(obj[i]);
			}
			return x;
			break;
		case "java.lang.String":
		default: //it's most likely a String or other individual value, return it as a Vector
			var x:java.util.Vector = new java.util.Vector();
			x.add(obj);
			return x;
			break;
	}
}





The Notes/Domino API will return either an individual element (e.g.- String) or java.util.Vector for a multi-value capable field. This provides a handling function to return the value(s) consistently formatted as a Vector. For the original and further discussion, please visit the article on my blog on the subject, https://edm00se.io/xpages/consistent-multivalue-formatting/ .

JavaScript (Server)
Eric McCormick
October 21, 2014 3:36 PM
Rating
26

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...