//by default we'll use an ascending sort var sortOrder2 = "asc"; //by default, we'll use a textnocase sort var sortType2 = "textnocase"; //by default, use ascii character 30 as the delim var delim2 = "."; //make an array to hold the sort stuff var sortArray = arraynew(1); //make an array to return var returnArray = arraynew(1); //grab the number of elements in the array (used in the loops) var count = arrayLen(arguments.aOfS); //make a variable to use in the loop var ii = 1; //if there is a 3rd argument, set the sortOrder if(structKeyExists(arguments, 'sortOrder')) sortOrder2 = arguments.sortOrder; //if there is a 4th argument, set the sortType if(structKeyExists(arguments, 'sortType')) sortType2 = arguments.sortType; //if there is a 5th argument, set the delim if(structKeyExists(arguments, 'delim')) delim2 = arguments.delim; //loop over the array of structs, building the sortArray for(ii = 1; ii lte count; ii = ii + 1) sortArray[ii] = arguments.aOfS[ii][arguments.key] & delim2 & ii; //now sort the array arraySort(sortArray,sortType2,sortOrder2); //now build the return array for(ii = 1; ii lte count; ii = ii + 1) returnArray[ii] = arguments.aOfS[listLast(sortArray[ii],delim2)]; //return the array return returnArray; var colNames = ""; var theQuery = QueryNew("tmp"); var i = 0; var j = 0; var c = 0; var foo = ""; var count = arrayLen(arguments.theArray); var col_num = 0; var item = ""; //if there's nothing in the array, return the empty query if (count eq 0) return theQuery; //get the column names into an array = colNames = structKeyArray(arguments.theArray[1]); col_num = ArrayLen(colNames); //build the query based on the colNames if ( arguments.forceColsToVarchar ) { theQuery = queryNew(arrayToList(colNames), RepeatString("varchar,", col_num)); arguments.allowComplexValues = false; } else theQuery = queryNew(arrayToList(colNames)); //add the right number of rows to the query queryAddRow(theQuery, count); //for each element in the array, loop through the columns, populating the query for(i=1; i LTE count; i=i+1) { item = arguments.theArray[i]; for(j=1; j LTE col_num; j=j+1) { foo = ''; if ( StructKeyExists(item, colNames[j]) ) foo = item[colNames[j]]; // Clear the value for this cell if it is not a Simple Value and allowComplexValues is false if ( !arguments.allowComplexValues AND !IsSimpleValue(foo) ) foo = ''; querySetCell(theQuery, colNames[j], foo, i); } } return theQuery; var order = "asc"; var i = 1; var j = 1; var thePosition = ""; var theList = ""; //by default, use ascii character 30 as the delim var delim2 = "|"; var sortOrder2 = "asc"; var arrayToReturn = ArrayNew(2); var sortArray = ArrayNew(1); var counter = 1; if(structKeyExists(arguments, 'sortOrder')) sortOrder2 = arguments.sortOrder; if(structKeyExists(arguments, 'delim')) delim2 = arguments.delim; for (i=1; i LTE ArrayLen(arguments.arrayToSort); i=i+1) { ArrayAppend(sortArray, arguments.arrayToSort[i][arguments.sortColumn]); } theList = ArrayToList(sortArray,delim2); ArraySort(sortArray, arguments.type, sortOrder2); for (i=1; i LTE ArrayLen(sortArray); i=i+1) { thePosition = ListFind(theList, sortArray[i],delim2); theList = ListDeleteAt(theList, thePosition,delim2); for (j=1; j LTE ArrayLen(arguments.arrayToSort[thePosition]); j=j+1) { arrayToReturn[counter][j] = arguments.arrayToSort[thePosition][j]; } ArrayDeleteAt(arguments.arrayToSort, thePosition); counter = counter + 1; } return arrayToReturn; "\G(\#ARGUMENTS.Delimiter#|\r?\n|\r|^)" & "(?:""([^""]*+(?>""""[^""]*+)*)""|" & "([^""\#ARGUMENTS.Delimiter#\r\n]*+))" ) ) /> return REFindNoCase("^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{16}$", arguments.inStr); var TempList = ""; var i = 0; /* Loop through the second list, checking for the values from the first list. * Add any elements from the second list that are found in the first list to the * temporary list */ for (i=1; i LTE ListLen(arguments.list2, arguments.delimiter); i=i+1) { if ( ListFindNoCase(arguments.list1, ListGetAt(arguments.list2, i, arguments.delimiter), arguments.delimiter) ) TempList = ListAppend(TempList, ListGetAt(arguments.list2, i, arguments.delimiter), arguments.delimiter); } Return TempList; var root = "query"; //the default name of each row var row = "row"; //make an array of the columns for looping var cols = listToArray(arguments.query.columnList); //which mode will we use? var nodeMode = "values"; //vars for iterating var ii = 1; var rr = 1; //vars for holding the values of the current column and value var thisColumn = ""; var thisValue = ""; //a new xmlDoc var xml = xmlNew(); //if there are 2 arguments, the second one is name of the root element if(structCount(arguments) GTE 2) root = arguments[2]; //if there are 3 arguments, the third one is the name each element if(structCount(arguments) GTE 3) row = arguments[3]; //if there is a 4th argument, it's the nodeMode if(structCount(arguments) GTE 4) nodeMode = arguments[4]; //create the root node xml.xmlRoot = xmlElemNew(xml,root); //capture basic info in attributes of the root node xml[root].xmlAttributes["columns"] = arrayLen(cols); xml[root].xmlAttributes["rows"] = arguments.query.recordCount; //loop over the recordcount of the query and add a row for each one for(rr = 1; rr LTE arguments.query.recordCount; rr = rr + 1){ arrayAppend(xml[root].xmlChildren,xmlElemNew(xml,row)); //loop over the columns, populating the values of this row for(ii = 1; ii LTE arrayLen(cols); ii = ii + 1){ thisColumn = lcase(cols[ii]); thisValue = query[cols[ii]][rr]; switch(nodeMode){ case "rows": xml[root][row][rr].xmlAttributes[thisColumn] = thisValue; break; case "columns": arrayAppend(xml[root][row][rr].xmlChildren,xmlElemNew(xml,thisColumn)); xml[root][row][rr][thisColumn].xmlAttributes["value"] = thisValue; break; default: arrayAppend(xml[root][row][rr].xmlChildren,xmlElemNew(xml,thisColumn)); xml[root][row][rr][thisColumn].xmlText = thisValue; } } } //return the xmlDoc return xml; var retArray = ArrayNew(1); var i = 1; var j = 1; var arrayCount = 1; var fldVal = ""; // loop over the idList for (i = 1; i lte #ListLen(arguments.idList)#; i = i + 1) { // loop over the arrayOfStructs to find the matching item with the ID for (j = 1; j lte #ArrayLen(arguments.arrayOfStructs)#; j=j+1) { // [MFC 2/20/09] Check if the values struct exists. Set fldVal variable. if ( structKeyExists(arguments.arrayOfStructs[j], "values") ) fldVal = arguments.arrayOfStructs[j].Values["#arguments.idFieldName#"]; else fldVal = arguments.arrayOfStructs[j][arguments.idFieldName]; if ( ListGetAt(arguments.idList,i) eq fldVal ) { retArray[arrayCount] = arguments.arrayOfStructs[j]; arrayCount = arrayCount + 1; } } } return retArray; var numWords = 0; var oldPos = 1; var i = 1; var strPos = 0; str = trim(str); str = REReplace(str,"[[:space:]]{2,}"," ","ALL"); numWords = listLen(str," "); if ( words gte numWords ) return str; for (i = 1; i lte words; i=i+1) { strPos = find(" ",str,oldPos); oldPos = strPos + 1; } if ( (len(str) lte strPos ) OR ( useEllipsis EQ false ) ) return left(str,strPos-1); else return left(str,strPos-1) & "..."; var binaryDoc = ''; // reset the binary doc value to null to start over request.binaryDoc = ""; /** * Converts a query object into an array of structures. * * @param query The query to be transformed * @return This function returns a structure. * @author Nathan Dintenfass (nathan@changemedia.com) * @version 1, September 27, 2001 */ var theArray = arraynew(1); var cols = ListtoArray(arguments.queryData.columnlist); var row = 1; var thisRow = ""; var col = 1; for(row = 1; row LTE arguments.queryData.recordcount; row = row + 1){ thisRow = structnew(); for(col = 1; col LTE arraylen(cols); col = col + 1){ if ( arguments.keysToLowercase ) thisRow[lcase(cols[col])] = arguments.queryData[cols[col]][row]; else thisRow[cols[col]] = arguments.queryData[cols[col]][row]; } arrayAppend(theArray,duplicateStruct(thisRow)); } return theArray; var struct = StructNew(); var i = 1; var pairi = ""; var keyi = ""; var valuei = ""; var qsarray = ""; var qs = arguments.inString; // default querystring value //if there is a second argument, use that as the query string if (arrayLen(arguments) GT 0) qs = arguments[1]; // Make sure all & are just & if ( FindNoCase("&",qs) EQ 1 ) qs = ReplaceNoCase(qs, "&", "&", "all"); //put the query string into an array for easier looping qsarray = listToArray(qs, "&"); //now, loop over the array and build the struct for ( i=1; i lte arrayLen(qsarray); i=i+1 ) { pairi = qsarray[i]; // Make sure all amp; are removed if ( FindNoCase("amp;",pairi) EQ 1 ) pairi = ReplaceNoCase(pairi, "amp;", "", "one"); keyi = listFirst(pairi,"="); // current key valuei = urlDecode(listRest(pairi,"=")); // current value // check if key already added to struct if ( structKeyExists(struct,keyi) ) struct[keyi] = listAppend(struct[keyi],valuei); // add value to list else structInsert(struct,keyi,valuei); // add new key/value pair } // return the struct return struct; var struct = structNew(); var increment = 1; var ii = 1; var rowsGotten = 0; //if reversing, we go backwards through the query if(arguments.reverse){ ii = arguments.query.recordCount; increment = -1; } //loop through the query, populating the struct //we do the while loop rather than a for loop because we don't know what direction we're going in while(rowsGotten LT arguments.query.recordCount){ struct[arguments.query[arguments.keyColumn][ii]] = arguments.query[arguments.valueColumn][ii]; ii = ii + increment; rowsGotten = rowsGotten + 1; } return struct; var currKey = ListFirst(arguments.keyList); // Current Key Variable // Check if current key exists in the struct if ( StructKeyExists(arguments.dataStruct, currKey) ) { // Check if we still have a sub struct if ( isStruct(arguments.dataStruct[currKey]) ) { // Recurse the remaining struct return structFindRecurse(arguments.dataStruct[currKey], ListDeleteAt(arguments.keyList,1)); } else { // Found what we needed, so return the struct key value return arguments.dataStruct[currKey]; } } else { // No match found, return empty string return ""; } var newQuery = QueryNew("temp"); var arrayCol = ArrayNew(1); var i = 1; var j = 1; arguments.csvString = trim(arguments.csvString); arrayCol = listToArray(listFirst(arguments.csvString,arguments.rowDelim),arguments.colDelim); for(i=1; i le arrayLen(arrayCol); i=i+1) queryAddColumn(newQuery, arrayCol[i], ArrayNew(1)); for(i=2; i le listLen(arguments.csvString,arguments.rowDelim); i=i+1) { queryAddRow(newQuery); for(j=1; j le arrayLen(arrayCol); j=j+1) { if ( listLen(listGetAt(arguments.csvString,i,arguments.rowDelim),arguments.colDelim) gte j ) { querySetCell(newQuery, arrayCol[j],listGetAt(listGetAt(arguments.csvString,i,arguments.rowDelim),j,arguments.colDelim), i-1); } } } return newQuery; var retStruct = duplicateStruct(arguments.struct1); // Set struct1 as the base structure var retStructKeyList = structKeyList(retStruct); var struct2KeyList = structKeyList(arguments.struct2); var currKey = ""; var i = 1; //DFTVYVS = Don't Forget To VAR Your Variables...Stupid // loop over the struct 2 key list for ( i = 1; i LTE ListLen(struct2KeyList); i = i + 1) { // current key currKey = ListGetAt(struct2KeyList, i); // reset the structKeyList retStructKeyList = structKeyList(retStruct); // Check if the current key is in the struct1 key list if ( ListFindNoCase(retStructKeyList, currKey) ) { // Check if have a sub-structure remaining if ( isStruct(retStruct[currKey]) AND isStruct(arguments.struct2[currKey]) ) StructInsert(retStruct, currKey, structMerge(retStruct[currKey], arguments.struct2[currKey]), true); else if ( isStruct(arguments.struct2[currKey]) ) { // Check if we still have a struct in arguments.struct2[currKey] StructInsert(retStruct, currKey, arguments.struct2[currKey], true); } else if(arguments.mergeValues and isSimpleValue(retStruct[currKey]) and isSimpleValue(struct2[currKey])) { //Check to see if we have simple values that can have a list merge StructInsert(retStruct, currKey, listAppend(retStruct[currKey],struct2[currKey]), true); } } else { StructInsert(retStruct, currKey, arguments.struct2[currKey], true); } } return retStruct; var csv = ""; var i = 1; var j = 1; if(arguments.cols is "") arguments.cols = arguments.data.columnList; if(arguments.headers IS "") arguments.headers = arguments.cols; arguments.headers = listToArray(arguments.headers); for(i=1; i lte arrayLen(arguments.headers); i=i+1) { csv = csv & """" & arguments.headers[i] & ""","; } csv = csv & chr(13) & chr(10); arguments.cols = listToArray(arguments.cols); for(i=1; i lte arguments.data.recordCount; i=i+1) { for(j=1; j lte arrayLen(arguments.cols); j=j+1) { csv = csv & """" & arguments.data[arguments.cols[j]][i] & ""","; } csv = csv & chr(13) & chr(10); } return csv; var row = ""; var col = ""; if ( arguments.q1.columnList NEQ arguments.q2.columnList ) { return arguments.q1; } for(row=1; row LTE arguments.q2.recordCount; row=row+1) { queryAddRow(arguments.q1); for(col=1; col LTE listLen(arguments.q1.columnList); col=col+1) querySetCell(arguments.q1,ListGetAt(arguments.q1.columnList,col), arguments.q2[ListGetAt(arguments.q1.columnList,col)][row]); } return q1; // Find the attribute in the tag var beginAttr = findNoCase(arguments.attribute, arguments.tag); var firstEqual = find("=", arguments.tag, beginAttr); // Handle quoted data var possibleQuote = mid(arguments.tag, firstEqual + 1, 1); var endAttr = ""; var retAttrVal = ""; if ( beginAttr GT 0 ) { // Check if we have a quote around the value if ( (possibleQuote EQ """") OR (possibleQuote EQ "'") ) { // Find the closing quote endAttr = findNoCase(possibleQuote, arguments.tag, firstEqual + 2); } else { // No quote, then find the next space endAttr = findNoCase(" ", arguments.tag, firstEqual); } // Get the value for the attr tag retAttrVal = mid(arguments.tag, firstEqual + 2, endAttr - firstEqual - 2 ); } var string = ""; //vars for use in the loop, so we don't have to evaluate lists and arrays more than once var ii = 1; var thisVar = ""; var thisIndex = ""; var array = ""; //put the query string into an array for easier looping array = listToArray(arguments.list,","); //now, loop over the array and rebuild the string for(ii = 1; ii lte arrayLen(array); ii = ii + 1) { thisIndex = array[ii]; thisVar = thisIndex; //if this is the var, edit it to the value, otherwise, just append if(not listFindnocase(arguments.listValue,thisVar)) string = listAppend(string,thisIndex,","); } var i=1; if ((NOT IsArray(a1)) OR (NOT IsArray(a2))) { writeoutput("Error in ArrayConcat()! Correct usage: ArrayConcat(Array1, Array2) -- Concatenates Array2 to the end of Array1"); return 0; } for (i=1;i LTE ArrayLen(a2);i=i+1) { ArrayAppend(a1, duplicateStruct(a2[i])); } return a1; // Thanks to the blog of Christian Cantrell for this one var bd = CreateObject("java", "java.math.BigDecimal"); var mode = "even"; var result = ""; if (ArrayLen(arguments) GTE 3) mode = arguments[3]; bd.init(arguments.numberToRound); if (mode IS "up") { bd = bd.setScale(arguments.numberOfPlaces, bd.ROUND_HALF_UP); } else if (mode IS "down") { bd = bd.setScale(arguments.numberOfPlaces, bd.ROUND_HALF_DOWN); } else { bd = bd.setScale(arguments.numberOfPlaces, bd.ROUND_HALF_EVEN); } result = bd.toString(); if(result EQ 0) result = 0; return result; var i = 0; var delim = ","; var asArray = ""; var set = StructNew(); if (ArrayLen(arguments) gt 1) delim = arguments[2]; asArray = ListToArray(lst, delim); for (i = 1; i LTE ArrayLen(asArray); i = i + 1) set[asArray[i]] = ""; return structKeyList(set, delim); var qstr = ""; var delim1 = "="; var delim2 = "&"; switch (ArrayLen(Arguments)) { case "3": delim2 = Arguments[3]; case "2": delim1 = Arguments[2]; } for (key in struct) { qstr = ListAppend(qstr, URLEncodedFormat(LCase(key)) & delim1 & URLEncodedFormat(struct[key]), delim2); } return qstr; var description = ''; var retUUID = arguments.uuid; var firstSet = ListFirst(arguments.uuid, "-"); var lastSet = ListLast(arguments.uuid, "-"); // Keep adding leading zero's until length is 8 WHILE ( LEN(firstSet) LT 8 ){ firstSet = "0" & firstSet; } // Keep adding ending zero's until length is 16 WHILE ( LEN(lastSet) LT 16 ){ lastSet = lastSet & "0"; } // Merge the firstSet and lastSet back to the UUID retUUID = firstSet & "-" & ListGetAt(arguments.uuid, 2, "-") & "-" & ListGetAt(arguments.uuid, 3, "-") & "-" & lastSet; return retUUID; if ( isSimpleValue( arguments.dataStruct ) ) return arguments.dataStruct; else return duplicate(arguments.dataStruct); // Removed the CS UDF duplicateBean() since it was copying and not duplicating /* if ( isSimpleValue( arguments.dataStruct ) ) return arguments.dataStruct; else if ( isQuery( arguments.dataStruct ) ) return duplicate(arguments.dataStruct); else return server.commonspot.udf.util.duplicateBean(arguments.dataStruct); */