//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; /** * Converts an array of structures to a CF Query Object. * 6-19-02: Minor revision by Rob Brooks-Bilson (rbils@amkor.com) * * Update to handle empty array passed in. Mod by Nathan Dintenfass. Also no longer using list func. * * @param Array The array of structures to be converted to a query object. Assumes each array element contains structure with same (Required) * @return Returns a query object. * @author David Crawford (rbils@amkor.comdcrawford@acteksoft.com) * @version 2, March 19, 2003 */ 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)); 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]]; if (NOT 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); i=i+1) { if (ListFindNoCase(arguments.list1, ListGetAt(arguments.list2, i))){ TempList = ListAppend(TempList, ListGetAt(arguments.list2, i)); } } Return TempList; /** * Generates an XMLDoc object from a basic CF Query. * * @param query The query to transform. (Required) * @param rootElement Name of the root node. (Default is "query.") (Optional) * @param row Name of each row. Default is "row." (Optional) * @param nodeMode Defines the structure of the resulting XML. Options are 1) "values" (default), which makes each value of each column mlText of individual nodes; 2) "columns", which makes each value of each column an attribute of a node for that column; 3) "rows", which makes each row a node, with the column names as attributes. (Optional) * @return Returns a string. * @author Nathan Dintenfass (nathan@changemedia.com) * @version 2, November 15, 2002 */ //the default name of the root element 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 IS false) ) { return left(str,strPos-1); } else { return left(str,strPos-1) & "..."; } // 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,duplicate(thisRow)); } /** * Converts a URL query string to a structure. * * @param qs Query string to parse. Defaults to cgi.query_string. (Optional) * @return Returns a struct. * @author Malessa Brisbane (cflib@brisnicki.com) * @version 1, April 11, 2006 */ //var to hold the final structure var struct = StructNew(); //vars for use in the loop, so we don't have to evaluate lists and arrays more than once 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]; //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]; // current pair keyi = listFirst(pairi,"="); // current key valuei = urlDecode(listLast(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; } 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 ""; } /** * Transform a CSV formatted string with header column into a query object. * * @param cvsString CVS Data. (Required) * @param rowDelim Row delimiter. Defaults to CHR(10). (Optional) * @param colDelim Column delimiter. Defaults to a comma. (Optional) * @return Returns a query. * @author Tony Brandner (tony@brandners.com) * @version 1, September 30, 2005 */ //function csvToQuery(csvString){ //var rowDelim = chr(10); //var colDelim = ","; //var numCols = 1; var newQuery = QueryNew(""); var arrayCol = ArrayNew(1); var i = 1; var j = 1; arguments.csvString = trim(arguments.csvString); //if(arrayLen(arguments) GE 2) arguments.rowDelim = arguments[2]; //if(arrayLen(arguments) GE 3) arguments.colDelim = arguments[3]; 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) ge j) { querySetCell(newQuery, arrayCol[j],listGetAt(listGetAt(arguments.csvString,i,arguments.rowDelim),j,arguments.colDelim), i-1); } } } //} var retStruct = Duplicate(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; /** * Transform a query result into a csv formatted variable. * * @param query The query to transform. (Required) * @param headers A list of headers to use for the first row of the CSV string. Defaults to cols. (Optional) * @param cols The columns from the query to transform. Defaults to all the columns. (Optional) * @return Returns a string. * @author adgnot sebastien (sadgnot@ogilvy.net) * @version 1, June 26, 2002 */ //function QueryToCsv(arguments.data){ var csv = ""; //var cols = ""; //var headers = ""; var i = 1; var j = 1; //if(arrayLen(arguments) gte 2) headers = arguments[2]; //if(arrayLen(arguments) gte 3) cols = arguments[3]; 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; //} /** * Concatenate two queries together. * * @param q1 First query. (Optional) * @param q2 Second query. (Optional) * @return Returns a query. * @author Chris Dary (umbrae@gmail.com) * @version 1, February 23, 2006 */ 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]); } // 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 ); } /** * Delete items from a list. * * @param variable An item, or a list of items, to remove from the list. (Required) * @param qs The actual list to parse. Can be blank. (Optional) * @return Returns a string. * @author Alessandro Chisari (ruchizzy@hotmail.com) * @version 1, May 17, 2006 */ //var to hold the final string 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, Duplicate(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;