JSON error

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 );
	}));
};

Open in new window


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/
LVL 5
IsaacSharePoint Client Side DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
Yes, I dud
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
did
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

IsaacSharePoint Client Side DeveloperAuthor Commented:
I also tried it this way but still get the same error:

function buildProjExecution(chartType) {  
   getProjects();
   
   arrProjs = _.uniqObject(arrProjs,true);
   
      $.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 i=0;
         $().SPServices({
                operation: "GetListItems",
                listName: "Project",
                async: false,
                CAMLViewFields: "<ViewFields><FieldRef Name='ProjNumber'></FieldRef><FieldRef Name='AmtProjected'></FieldRef></ViewFields>",    
		CAMLRowLimit: 20, 
		CAMLQuery: "<Query><Where><And><Geq><FieldRef Name='ObDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+beginFY+"</Value></Geq><Leq><FieldRef Name='ObligationDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'>"+endFY+"</Value></Leq></And></Where></Query>",
                completefunc: function (xData, Status) {
                    $(xData.responseXML).SPFilterNode("z:row").each(function () {
							ProjectItem = new Object();
							ProjectItem.projNumber = $(this).attr("ows_ProjNumber");
							ProjectItem.amtProjected = $(this).attr("ows_AmtProjected");		
							ProjectDataArray[i] = ProjectItem;
							i++;
                    });
                }
            });
}

/*
@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 );
	}));
};

Open in new window


Did I do this part correct?
/*
@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 );
	}));
};

Open in new window

0
leakim971PluritechnicianCommented:
did you add it before your script?

<script src="underscore.js"></script>
<script src="youscript.js"></script>

And not :

<script src="youscript.js"></script>
<script src="underscore.js"></script>
0
Rainer JeschorCommented:
Hi,
sorry to bring this question to a different road, but I made some good experiences with another library: linq.js (http://linqjs.codeplex.com/)

I put up a sample here:
http://jsfiddle.net/EE_RainerJ/FCYFP/
(simply created an array with 3 distinct elements but added them multiple times).

Con of this library is that the documentation and samples are sometimes really pure, but the Linq syntax and the implemented functions look very promising and I was nearly always able to get to the point what I wanted.

HTH
Rainer
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
Sorry for the late response...I had to run some errands.

 leakim971, I added the library before my script.

Rainer, wow! That seems very powerful.  I'll give that a try also.
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
Rainer,

Nothing happens when i try what you have in js fiddle....I don't even get any errors.
Some of my "ProjectedAmount" is blank.  Maybe that's why.  How do I check for undefined/blank with the linq?
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
I get an error now.... It say "E is undefined"
0
IsaacSharePoint Client Side DeveloperAuthor Commented:
Do I need more than just "jquery.linq.min.js" library?
0
Rainer JeschorCommented:
Hi,
sorry for the late reply.
Hm, the script on jsfiddle works on IE9, IE10 and FF23.
I used the linq.js only - not the jquery one as I could not find any online version to be used (linked) by jsFiddle.
It seems that the public reference is not the latest version (which could be downloaded from Codeplex).
In jsFiddle I used the shortcut "E" for "Linq.Enumerable" as using Enumerable leads towards an "Undefined".
Had just a quick look into the JS sources and the "full" version has to be used with "Linq.Enumerable" whereas the minified version is just using "Enumerable".
In the download ZIP there is also a HTML page where you can test the Ling expressions.
And as far as I can see, jQUery and the jquery.linq.min.js should be sufficient.
HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.