troubleshooting Question

JSON error

Avatar of Isaac
IsaacFlag for United States of America asked on
JavaScriptjQuery
11 Comments1 Solution509 ViewsLast Modified:
I get the error,

Message: Object doesn't support this property or method


function buildProjExecution(chartTy<wbr ></wbr>pe) {  
alert("chartType: "+chartType);
   getProjects();
   //var ProjectItem = []; // Initializes the array
   arrProjs = _.uniqObject(arrProjs,true<wbr ></wbr>);
   
   //arrProjs = _.uniq(['ACGY20137912PB','<wbr ></wbr>ACGY201379<wbr ></wbr>12PB','ACG<wbr ></wbr>Y20137912P<wbr ></wbr>B','ACGS20<wbr ></wbr>135001-1',<wbr ></wbr>'ACGS20135<wbr ></wbr>001-1','AC<wbr ></wbr>GS20135001<wbr ></wbr>-2']);
      $.each(ProjectDataArray, function (index, value) {																			
		alert(index + ':' + value);
    });
   alert("Prog Num: "+arrProjs.length);  //<-- 20 values here also after the uniq()
}


//Get values into an array so I can use the _.uniq() to remove the duplicates so I can add funding amount
function getProjects() {

					var fiscalYear = (new Date).getFullYear();					
					var prevYear = fiscalYear - 1;
					beginFY = prevYear + "-10-01"; // 2012-10-01
					endFY = fiscalYear + "-09-30"; // 2013-09-30
					var i=0;
         $().SPServices({
                operation: "GetListItems",
                listName: "ER_Projects",
                async: false,
                CAMLViewFields: "<ViewFields><FieldRef Name='ProjectNumber'></Fie<wbr ></wbr>ldRef><Fie<wbr ></wbr>ldRef Name='AmountProjected'></F<wbr ></wbr>ieldRef></<wbr ></wbr>ViewFields<wbr ></wbr>>",    
		CAMLRowLimit: 20, 
		CAMLQuery: "<Query><Where><And><Geq><<wbr ></wbr>FieldRef Name='ObligationDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+beginFY+<wbr ></wbr>"</Value><<wbr ></wbr>/Geq><Leq><wbr ></wbr><FieldRef Name='ObligationDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+endFY+"<<wbr ></wbr>/Value></L<wbr ></wbr>eq></And><<wbr ></wbr>/Where></Q<wbr ></wbr>uery>",
                completefunc: function (xData, Status) {
                    $(xData.responseXML).SPFil<wbr ></wbr>terNode("z<wbr ></wbr>:row").eac<wbr ></wbr>h(function<wbr ></wbr> () {
							/*ProjectItem = new Object();
							ProjectItem.projectNumber = $(this).attr("ows_ProjectN<wbr ></wbr>umber");
							ProjectItem.amountProjecte<wbr ></wbr>d = $(this).attr("ows_AmountPr<wbr ></wbr>ojected");<wbr ></wbr>		
							ProjectDataArray[i] = ProjectItem;
							i++;*/
							var tempProject = new Object();
                        tempProject["ProjectNumer"<wbr ></wbr>] = $(this).attr("ows_ProjectN<wbr ></wbr>umber");	
						tempProject["AmountProject<wbr ></wbr>ed"] = $(this).attr("ows_AmountPr<wbr ></wbr>ojected");<wbr ></wbr>	
						arrProjs.push(tempProject)<wbr ></wbr>;
							
							/*
						var tempProject = new Object();
                        tempProject["ProjectNumer"<wbr ></wbr>] = $(this).attr("ows_ProjectN<wbr ></wbr>umber");	
						tempProject["AmountProject<wbr ></wbr>ed"] = $(this).attr("ows_AmountPr<wbr ></wbr>ojected");<wbr ></wbr>	
						arrProjs.push(tempProject)<wbr ></wbr>;*/
                    });
                }
            });
}

/*
@function _.uniqObjects
@require Underscore.js and json.stringify
@purpose return an array of objects without duplicated objects.
*/
_.uniqObjects = function( arr ){
	return _.uniq( _.collect( arr, function( x ){
		return JSON.stringify( x );
	}));
};

I got the idea from this site
http://bateru.com/news/2012/03/code-of-the-day-get-unique-objects-from-an-array-of-json-objects/
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros