• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

JQuery Sharepoint List Issue with If Function

Hello,

I have a java script which I am using to try and return the number of values in a sharepoint list that meet the criteria of being created in Period 2.

The script also does a count of the total number of entries in the list.

Currently, the script returns a result only if the following section is commented out. I've debugged the script and can see that there is a problem arround the datavalues that it is populated with. Screenshot attached.

//count number of lines in period
//      if ( periodValue === $node.attr("EM_REPORTING_PERIOD") ) {
//	numOpenedInPeriod++;}

Open in new window


Can anybody tell me what is wrong with the script and why it doesn't return a defined value for the sharepoint column to compare against?

I added  "alert($node.attr("EM_REPORTING_PERIOD"));" to see what was in the attribute & it just reports undefined.


Thanks

Full Code:

<script type="text/javascript" src="http://mynationwideteam/sites/fin_comms_tech_serv/Javascript/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="http://mynationwideteam/sites/fin_comms_tech_serv/Javascript/jquery.SPServices-0.7.1a.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
   //define local variables

   var numOfLines = 0, numOpenedInPeriod = 0 ;
   var periodValue = 2; // this will be set by drop down on going

  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "EM Exception Log",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery: "<Query><Where><Neq><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Neq></Where></Query>",

    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var $node = $(this);
      numOfLines++;

//count number of lines in period
     if ( periodValue === $node.attr("EM_REPORTING_PERIOD") ) {	numOpenedInPeriod++;}

      //alert($node.attr("EM_REPORTING_PERIOD"));


      //alert(numOpenedInPeriod);

      //alert(numOfLines);

      });

var output = "<table><tr><td><h3>Total Number of Lines: " + numOfLines + "</h3></td></tr>" + "<tr><td><h3>Total Open In Period 2: " + numOpenedInPeriod + "</h3></td></tr></table>";


//Append output to the DOM.
$("#results").append( output );

   }
  });
});
</script>
<div id='results'></div>

Open in new window

-node-invalid-number-of-paramete.jpg
0
bedsingar
Asked:
bedsingar
  • 2
  • 2
1 Solution
 
ChrisCommented:
you could try logging to console $node. Perhaps it's not what you think it is.

console.log($node);

If you view this in firebug, you'll see all the info on the object and should be able to work out if you have the correct element.
0
 
bedsingarAuthor Commented:
Hi,

Firebug is a Firefox addin isn't it? - I'm unfortunately restricted to using Internet explorer and can't install addins due to the admin policy.

Can I do this in IE Debug also? (As per the screenshot)

Thanks
0
 
BardobraveCommented:
Well, if $node.attr("EM_REPORTING_PERIOD") returns undefined is because that element isn't on your page.

It could be two things:
1) $node is not defined, maybe because the node you are trying to load and reference on your javascript is not on the page.

2) There is no EM_REPORTING_PERIOD attribute on the element referenced by $node.

You can check on your alert which of two options is just doing alert($node); if the element is on the page and is well referenced you should receive something like "[object Object]", if you receive here undefined then check what's happening with this node and why it's not being correctly loaded.

If the node is correctly loaded you should check on the page why it doesn't has the attribute you are asking for "EM_REPORTING_PERIOD" maybe there is a spelling error when it's being created on the page code, or maybe it's not being loaded...
0
 
ChrisCommented:
Unfortunately the Dev Tools in IE are somewhat lacking. In firebug if you console.log an object you're able to click the item in the log and view all it's details. In IE when you do the same you literally just get a line in the log saying:

LOG: [object Object]

It will at least tell you if you've got an object in the variable but you aren't getting much more info than that.
0
 
bedsingarAuthor Commented:
Found it finally ... $node.attr("ows_EM_REPORTING_PERIOD")

I missed off the ows_ .... In the mean time I'd completely re-written the code to take another approach.

Thanks for all your contributions.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now