Getlistitems first non blank value

Sep 23, 2011 at 6:18 PM
Edited Sep 23, 2011 at 6:20 PM

I have a list with time schedules. For an ADA complaint page I have taken the data from each column and am writting it left to right. I have a decscription field. Only the first row item has  a value, if not the value would be the same for each item in that column. After I build my table I want to write the description, but I only want to search for the first one, or only write it once. I am not sure how to look for the first non blank on a specific column and return that single value. any suggestions?

Sep 24, 2011 at 2:10 AM
I think all you need to do is a for loop (or use the .each() jQuery function) to loop through the rows until you hit a non-blank value. Or am I missing some nuance?

Sep 24, 2011 at 3:21 AM
Thanks for getting back to me. There is a little more to this. Let me try to explain the list. Besides being a time schedule each column of times has 6 types of routes. If I build a table for column1 "inbound" routes it will return about 24 route times from the column. What I am trying to do is add a description before the table pulling it from the same list. Knowing people can make mistakes I only need to pull the description once or find the first one matching the results of my original query for inbound times. I did not want to add a second Spservices function. I am trying to figure out how to incorporate a single Description, from Description column, with all the items from column1, inbound route times. 
Have I confused you yet? ;)


Sep 26, 2011 at 12:09 PM

Yes, you've confused me. I still think it's a matter of looping through your items to determine the value you need, though.


Sep 26, 2011 at 2:47 PM
Edited Sep 26, 2011 at 3:09 PM

I cant figure out how to add that loop to what I already have. here is an image of my sample data, Would you my taking a few minutes to offer a little help, please?

This is an image of the output I am trying to achieve. the red text is the description I am trying to add. The srcipt below builds the table, I just need to add the description above it.


this is the code I am using. Can you provide any assistance?

<div id="route"></div>

<script type="text/javascript">
	var rte= "AR6-WI";
	var stype = "Weekday Inbound";
	var stop1 = "Rosa Parks &amp; FSCJ Station";
	var stop2 = "Town &amp; Country";
	var stop3 = "University &amp; Merrill";
	var stop4 = "University &amp; Ft. Caroline";
	var stop5 = "Ft. Caroline &amp; Townsend";
	var stop6 = "Walmart &amp; Tredinick";
	var stop7 = "Regency Square Hub";

	var ln = "Bus Route AR6";  // list name
	var tables = "<a name='" + stype + "' id='" + stype + "'></a>";
			tables += "<a name='"+ stype + "1' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "1'></table><br>";
			tables += "<a name='"+ stype + "2' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "2'></table><br>";
			tables += "<a name='"+ stype + "3' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "3'></table><br>";
			tables += "<a name='"+ stype + "4' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "4'></table><br>";
			tables += "<a name='"+ stype + "5' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "5'></table><br>";
			tables += "<a name='"+ stype + "6' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "6'></table><br>";
			tables += "<a name='"+ stype + "7' id='" + stype + "1'></a>";
			tables += "<table id='" + rte + "7'></table><br>";




var q = "<Query><Where><Eq><FieldRef Name='Schedule' /><Value Type='Choice'>"+stype+"</Value></Eq></Where><OrderBy><FieldRef Name='Ordering' Ascending='True' /></OrderBy></Query>";
var v = "<ViewFields><FieldRef Name='Title' /><FieldRef Name='RouteName' /><FieldRef Name='Schedule' /><FieldRef Name='RosaParksFSCJStation' /><FieldRef Name='TownCountry' /><FieldRef Name='UniversityMerrill' /><FieldRef Name='UniversityFtCaroline' /><FieldRef Name='FtCarolineTownsend' /><FieldRef Name='WalmartTredinick' /><FieldRef Name='RegencySquareHub' /><FieldRef Name='RouteDescription' /></ViewFields>";

    operation: "GetListItems",
	webURL: "/SiteDirectory/marketing",
	async: false,
    listName: ln,
	CAMLQuery: q,
    CAMLViewFields: v, 
    completefunc: function (xData, Status) {
		var strHtml1 = "<caption>" + stop1 + "</caption><tr class='routerow'>"; 
		var strHtml2 = "<caption>" + stop2 + "</caption><tr class='routerow'>"; 
		var strHtml3 = "<caption>" + stop3 + "</caption><tr class='routerow'>";
		var strHtml4 = "<caption>" + stop4 + "</caption><tr class='routerow'>"; 
		var strHtml5 = "<caption>" + stop5 + "</caption><tr class='routerow'>"; 
		var strHtml6 = "<caption>" + stop6 + "</caption><tr class='routerow'>";
		var strHtml7 = "<caption>" + stop7 + "</caption><tr class='routerow'>"; 
	  $(xData.responseXML).find("[nodeName='z:row']").each(function(i) {
			var routestop1 = $(this).attr("ows_RosaParksFSCJStation");
			var routestop2 = $(this).attr("ows_TownCountry");
			var routestop3 = $(this).attr("ows_UniversityMerrill");
			var routestop4 = $(this).attr("ows_UniversityFtCaroline");
			var routestop5 = $(this).attr("ows_FtCarolineTownsend");
			var routestop6 = $(this).attr("ows_WalmartTredinick");
			var routestop7 = $(this).attr("ows_RegencySquareHub");
			var desc = $(this).attr("ows_RouteDescription");

			if(i%7 != 0) 	{
				strHtml1 += "<td class='routetime'>" + routestop1 + "</td>";
				strHtml2 += "<td class='routetime'>" + routestop2 + "</td>";
				strHtml3 += "<td class='routetime'>" + routestop3 + "</td>";
				strHtml4 += "<td class='routetime'>" + routestop4 + "</td>";
				strHtml5 += "<td class='routetime'>" + routestop5 + "</td>";
				strHtml6 += "<td class='routetime'>" + routestop6 + "</td>";
				strHtml7 += "<td class='routetime'>" + routestop7 + "</td>";
							} else if( i%7 == 0) 	{
				strHtml1 += "</tr><tr class='routerow'><td class='routetime'>" + routestop1 + "</td>";	
				strHtml2 += "</tr><tr class='routerow'><td class='routetime'>" + routestop2 + "</td>";	
				strHtml3 += "</tr><tr class='routerow'><td class='routetime'>" + routestop3 + "</td>";
				strHtml4 += "</tr><tr class='routerow'><td class='routetime'>" + routestop4 + "</td>";	
				strHtml5 += "</tr><tr class='routerow'><td class='routetime'>" + routestop5 + "</td>";
				strHtml6 += "</tr><tr class='routerow'><td class='routetime'>" + routestop6 + "</td>";
				strHtml7 += "</tr><tr class='routerow'><td class='routetime'>" + routestop7 + "</td>";


     strHtml1 += "</tr>";
	 strHtml2 += "</tr>";
	 strHtml3 += "</tr>";
	 strHtml4 += "</tr>";
	 strHtml5 += "</tr>";
	 strHtml6 += "</tr>";
	 strHtml7 += "</tr>";


Sep 30, 2011 at 4:36 AM

From what you're showing, I'd consider rethinking your list structure. Some of the information is at the route level and some of it is at the stop level. You should build two separate lists and use them relationally. The other thing that leads me to say that is that you have column names which represent the stop names rather than just a column called "Stop" or something.