Skip to main content
added 2373 characters in body
Source Link
<script type="text/javascript">

$( document ).ready(function() {

alert( "ready!" );

});

var method = "GetListItems";                  
var webURL =  $().SPServices.SPGetCurrentSite() ;                      
var list = "Dashboard";                       
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"<+"
</ViewFields>"; 
var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";
         

$().SPServices

        ({

                    operation: method,

                    async: false,  
                    
                    webURL: webURL,

                    listName: list,

                    CAMLViewFields: "<ViewFields Properties='True' />",
               
                    CAMLQuery: query, 
                    
                    // Override the default view rowlimit and get all appropriate rows
                CAMLRowLimit: 0,
                    
 
                    completefunc: function (xData, Status)
       {

 var itemCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");
  alert(itemCount);       

// 1. Get the raw data from the Sharepoint Web Services API.

var subtasks = $(xData.responseXML).SPFilterNode("z:row"); //This is the list of all subtasks

// 2. Need to break it down into arrays -- one per category
// and 3. Loop thru each subtask to find the most high-severity status per category.

var categories = [];
var highest_severity = 0;

// if (typeof(last_category) !== 'undefined') 
var last_category = 'A2';
for(x=0; x<subtasks.length; x++)

{

var category = subtasks[x].getAttribute('ows_LinkTitle').split(".", 1)[0]; 
//e.g. A3

if(category != last_category){
    categories[last_category.replace('A', '')] = highest_severity;
    last_category = category; // Set up for the new category.
    highest_severity = 0;
}

var subtask_status = subtasks[x].getAttribute('ows_Status'); //e.g. "High Risk"
switch(subtask_status){

        case "High Risk": current_row_severity = 5;
            break;

        case "Moderate Risk": current_row_severity = 4;
            break;

    case "Accepted Risk": current_row_severity = 3;
            break;

        case "On Track": current_row_severity = 2;
            break;

        case "Complete": current_row_severity = 1;
            break;

        default: current_row_severity = 0;
            break;

    };

if(current_row_severity > highest_severity)

    highest_severity = current_row_severity;
} 


    // 4. Color the status box according to the most high-severity status for each.
    var colorArray = ['#EFEFEF', '#E6F2FF', '#C1E1A6', '#FFFFCC', '#FFD9B3', '#EBCFC4'];
for(x=2; x<34; x++) // looping through each of the status boxes, one at a time
{
    var status_box_element = document.getElementById('A' + x);
    var newColor = colorArray[categories[x]];
    status_box_element.style.backgroundColor = newColor;

}   
                       }

       });
</script> 
var method = "GetListItems";                  
var webURL =  $().SPServices.SPGetCurrentSite() ;                      
var list = "Dashboard";                       
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>"; 
var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";       

$().SPServices

        ({

                    operation: method,

                    async: false, 

                    webURL: webURL,

                    listName: list,

                    CAMLViewFields: "<ViewFields Properties='True' />",

                    CAMLQuery: query,                                                                                     
 
                    completefunc: function (xData, Status)

                     {
<script type="text/javascript">

$( document ).ready(function() {

alert( "ready!" );

});

var method = "GetListItems";               
var webURL =  $().SPServices.SPGetCurrentSite() ;                      
var list = "Dashboard";                       
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"
</ViewFields>"; 
var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";
         

$().SPServices

        ({

                    operation: method,

                    async: false,  
                    
                    webURL: webURL,

                    listName: list,

                    CAMLViewFields: "<ViewFields Properties='True' />",
               
                    CAMLQuery: query, 
                    
                    // Override the default view rowlimit and get all appropriate rows
                CAMLRowLimit: 0,
                    
                    completefunc: function (xData, Status)
       {

 var itemCount = $(xData.responseXML).SPFilterNode("rs:data").attr("ItemCount");
  alert(itemCount);       

// 1. Get the raw data from the Sharepoint Web Services API.

var subtasks = $(xData.responseXML).SPFilterNode("z:row"); //This is the list of all subtasks

// 2. Need to break it down into arrays -- one per category
// and 3. Loop thru each subtask to find the most high-severity status per category.

var categories = [];
var highest_severity = 0;

// if (typeof(last_category) !== 'undefined') 
var last_category = 'A2';
for(x=0; x<subtasks.length; x++)

{

var category = subtasks[x].getAttribute('ows_LinkTitle').split(".", 1)[0]; 
//e.g. A3

if(category != last_category){
    categories[last_category.replace('A', '')] = highest_severity;
    last_category = category; // Set up for the new category.
    highest_severity = 0;
}

var subtask_status = subtasks[x].getAttribute('ows_Status'); //e.g. "High Risk"
switch(subtask_status){

        case "High Risk": current_row_severity = 5;
            break;

        case "Moderate Risk": current_row_severity = 4;
            break;

    case "Accepted Risk": current_row_severity = 3;
            break;

        case "On Track": current_row_severity = 2;
            break;

        case "Complete": current_row_severity = 1;
            break;

        default: current_row_severity = 0;
            break;

    };

if(current_row_severity > highest_severity)

    highest_severity = current_row_severity;
} 


    // 4. Color the status box according to the most high-severity status for each.
    var colorArray = ['#EFEFEF', '#E6F2FF', '#C1E1A6', '#FFFFCC', '#FFD9B3', '#EBCFC4'];
for(x=2; x<34; x++) // looping through each of the status boxes, one at a time
{
    var status_box_element = document.getElementById('A' + x);
    var newColor = colorArray[categories[x]];
    status_box_element.style.backgroundColor = newColor;

}   
                       }

       });
</script> 
Source Link

Sharepoint 2010 SPServices and GetListItem Problems with Adding New List Item

I'm using SharePoint 2010, SPServices and the GetListItems method to retrieve items from a list. The list has 31 categories such as A2, A3, A4... until A32. There are also sub categories such as, A2.1, A2.2, A2.3, etc.

The list data outputs into 31 boxes coded in HTML and JavaScript assigns a color to each box according to the highest severity level (high risk=red, moderate risk=orange...)

There will always be 31 colored boxes (A2 thru A32) and I don't need to add new boxes. The JavaScript works where it cycles through all subcategories and correctly outputs the color to the parent. If I EDIT a list item the color changes correctly and if I DELETE a list item, the page updates.

The problem is when I ADD a new list item (A2.1.1) SharePoint isn't seeing the latest list item that was just added until I add a another list item then it will update the previous HTML box color. My question is if the SPServices GetListItem method doesn't actually retrieve the current data set. I've inserted a CAMLRowLimit: 0, and that didn't work.

Has anyone heard of GetListItems not always returning the current data set? When I refresh the browser for a split second all of the boxes change to the previous browser version history and then the page loads.

var method = "GetListItems";                  
var webURL =  $().SPServices.SPGetCurrentSite() ;                      
var list = "Dashboard";                       
var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>"; 
var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";       

$().SPServices

        ({

                    operation: method,

                    async: false, 

                    webURL: webURL,

                    listName: list,

                    CAMLViewFields: "<ViewFields Properties='True' />",

                    CAMLQuery: query,                                                                                     

                    completefunc: function (xData, Status)

                     {