Quantcast
Viewing all articles
Browse latest Browse all 6517

New Post: global variables

To address a particular situation occurring in the asynchronous processing of a current project, I would like to have a set of values that I build dynamically throughout the routine where these values are available at the end of the application. I set two global variables, then play with them in one routine. Within that routine (doStuff), the values are available as expected. 

But I want that global variable available when the whole process ends. No matter how wonderfully the values appear during doStuff, by the time the process has finished, there's nothing available.

I've worked out all the situations regarding asynchronous processing to the extent I understand them and am having no luck. Any ideas?

<script language="javascript" type="text/javascript"> var devGFSSEForms = function() {var arHoldAll = [];var arCurrentDupes = [];
...//as it stands, this first routine runs whenever the page is accessed
		$(document).ready(function() {  
...
			$().SPServices({
				operation:  "GetListItems",  
				listName: "{D3795486-9926-424E-8F14-59BE5DB65BA8}",	//dev GFSSEForm
				CAMLViewFields: "<ViewFields><FieldRef Name='LinkFilename'/><FieldRef Name='Exported' /></ViewFields>", 
				completefunc: function (xData, Status) { 
...
				}  //completefunc
			});  //SPServices
		});  //document.readyreturn {

		processRecord: function () {var myQueryOptions = "<QueryOptions />";var myQuery = "<Query><OrderBy><FieldRef Name='Created_x0020_Date' /></OrderBy><Where><Eq><FieldRef Name='Exported' /><Value Type='Integer'>0</Value></Eq></Where></Query>";	//user, action but no attention to Orphan status
			$().SPServices({
				operation:  "GetListItems",
				listName: "{D3795486-9926-424E-8F14-59BE5DB65BA8}",	//development
				CAMLViewFields: "<ViewFields><FieldRef Name='LinkFilename'/><FieldRef Name='Exported' /></ViewFields>", 
				CAMLQuery: myQuery,
				CAMLQueryOptions: myQueryOptions,
				completefunc: function (xData, Status) {
					$(xData.responseXML).SPFilterNode('z:row').each(function() {
...
					});  //each()
					$.each(arIDs, function(index, value) {var promise = $.ajax({
							type:"GET",
							url:"GFSSEForm/"+ arIDs[index][2],
							dataType:"text"
						});
						promise.done(doStuff);	//magically passes the data along, too
						promise.fail(function() {alert("failed to open this eform: "+ arIDs[index][2]);});
					});  //each
				}  //completefunc
			});  //SPServices// would like arCurrentDupes to be available here
		}  // processRecord()
	};	// public method processRecord() [return]function doStuff(data) {
...var useThis = arValues;if(arValues[0] != "") {var strName = arValues[0];var strAction = arValues[5].substring(0,1);var strCombo = strName+":"+strAction;if($.inArray(strCombo, arHoldAll) > -1) arCurrentDupes.push(strCombo);else arHoldAll.push(strCombo);	//this works
					findExisting(strName, strAction);	// calls SPServices
				}	// if username wasn't empty
				arValues = useThis;	//this works
...
					writeNew();
...
		}  // doStuff()function writeNew() {
...
			arValues = strUseThis.split(",");for(i=0; i<iFields; i++) {
				strTest = arValues[i];if(strTest.length > 255) strTest = strTest.substring(0,255);
				strField = arFields[i]; 
				vpairs.push([strField,strTest]);
			}
			$().SPServices({
				operation: "UpdateListItems",
				batchCmd: "New",
				listName: "{37229D49-3F6D-4812-A2F0-A0DC55B89DD1}",  //development list
				valuepairs: vpairs,
				completefunc: function(xData, Status) {
...
				}	//completefunc
			}); //SPServices

		}  // writeNew()

...
		function findExisting(user, action) {var queryOptions = "<QueryOptions />";var query = "<Query><Where><And><And><Eq><FieldRef Name='Title' /><Value Type='Text'>"+ user + "</Value></Eq><BeginsWith><FieldRef Name='col05x' /><Value Type='Text'>"+ action + "</Value></BeginsWith></And><Neq><FieldRef Name='Orphan' /><Value Type='Integer'>1</Value></Neq></And></Where></Query>";  //CAML looks for existing items having same name and action, ignoring any that have already been marked as orphans
			$().SPServices({
				operation:  "GetListItems",
	      async: false,		//required!!!!! ; not used: no stack overflow, runs Orphan; use: stack overflow, no Orphan
				listName: "{37229D49-3F6D-4812-A2F0-A0DC55B89DD1}",	//development GFSSVerified list
				CAMLViewFields: "<ViewFields><FieldRef Name='Title'/><FieldRef Name='col05x' /></ViewFields>", 
				CAMLQuery: query,
				CAMLQueryOptions: queryOptions,
				completefunc: function (xData, Status) {var iCount = parseInt($(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount"));if(iCount > 0) {...}
...  //in the current data set I'm using, there is never a reason to come here
				}  //completefunc
			});  //SPServices
		}

...
  }(); //devGFSSEForms</script>  
"divId">

<button id="btnInitiate" onclick="devGFSSEForms.processRecord()">Click, to export to SharePoint</button>

"showErrors">
"results">


Viewing all articles
Browse latest Browse all 6517

Trending Articles