Showing posts with label SPServices. Show all posts
Showing posts with label SPServices. Show all posts

Thursday, January 20, 2011

SPServices & CAML Query Options

This is a strange behaviour when using JQuery's SPServices on a list with multi-valued person/group field.

Operation: "GetListItems"
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /></ViewFields>"
CAMLQuery: "<Query></Query>"

E.g. If the list has this item: [ID=1, Title=My First Item, PersonsResponsible=Test User A; Test User B, Status=Pending], then the output of the method call would have 2 rows:
- Row 1: [ID=1, Title=My First Item, PersonsResponsible=Test User A]
- Row 2: [ID=1, Title=My First Item, PersonsResponsible=Test User B]
* Status field does not appear because not part of the ViewFields. However, PersonsResponsible appear because it is a mandatory column.

I'm not too sure why 2 rows of result are returned (could it be a bug?) but to solve this problem, you simply have to add
CAMLQueryOptions: "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>"

This way, the method call correctly returns 1 row [ID=1, Title=My First Item]

Tuesday, May 4, 2010

SPServices

$().SPServices.SPGetCurrentSite()
$().SPServices.SPGetCurrentUser()

Wednesday, January 20, 2010

I'm loving JQuery

I would have to admit that when I was given my first Javascript and JQuery task, I had absolutely NO interest or passion in that language due to its unstructured-ness and lack of useful code-writing tools. Note: I came from a Java and .NET background and declaring variables without defining the type (int, string, etc) feels really really strange.

I am currently working on my third JS & JQuery project (I mostly copied codes from the net for my first 2 projects) and I starting to see the LIGHT! The unstructured-ness of things has been clouded by how easy it is to get what I want! Minimal coding/scripting was the highlight of the day!

I am proud to say that I am a JQuery convert and here are some tips to help everyone kickstart their coding-life transformation! :)

Important important reference: http://docs.jquery.com/
Here you'll get all the JQuery APIs properly documented.

To refer to any element in the HTML page (or select them, in JQuery language), use $("#id") where id is the id name of the element. You can also use $(element) which selects all the generic elements in the page. Example: $(a) selects all the <a> in the page! More selectors here. Once you "selected" the element, you can manipulate it easily (attributes, click/hover functions, etc).

Next we have the document ready function.
$(document).ready(function() {
// function code here
});
This function is called when the page is loaded.

and the connection with SharePoint Services. Many thanks to the kind people at Sympraxis Consulting LLC that made SP Programming much simpler and light-weighted!


Tuesday, November 17, 2009

Get files in SP folder using JQuery and SPServices

$().SPServices({

operation: "GetListItems",
webURL: "http://yourSite",
listName: "My Documents",
CAMLViewFields: "<ViewFields>\
<FieldRef Name='Title'/>\

<FieldRef Name='Category'/>
</ViewFields>"
,
CAMLQuery: "<Query><Where><Contains>\
<FieldRef Name='FileRef' />\

<Value Type='Text'>" + folderName + "</Value></Contains></Where></Query>", CAMLQueryOptions: "<QueryOptions><Folder>"
+ folderName + </Folder></QueryOptions>",
completefunc: function(xData2, Status) {
// enter code here
});

});

Monday, November 16, 2009

Get list items using JQuery and SPServices

<html
xmlns="http://www.w3.org/1999/xhtml"
>
<
head
runat="server">


<
title></title>

<
script
src="jquery.min.js"
type="text/javascript"></script>
<
script
src="jquery.SPServices.min.js"
type="text/javascript"></script>
<
script
src="print_r.js"
type="text/javascript"></script>

<
script
type="text/javascript">


$(document).ready(function() {

waitMessage = "<table width='100%' align='center'><tr><td align='center'>a</td></tr></table>";

$("#WSOutput").html(waitMessage).SPServices(

operation: "GetListItems",
webURL: "http://yoursite",
listName: "Training Programmes",
CAMLViewFields: "<ViewFields><FieldRef Name='Course_x0020_Name'/>\
<FieldRef Name='Course_x0020_Outline'/>\
<FieldRef Name='Code'/><FieldRef Name='Attachments'/></ViewFields>"
,
CAMLQuery: "<Query></Query>",
CAMLRowLimit: 10000,
CAMLQueryOptions: "<QueryOptions><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls></QueryOptions>",
completefunc: function(xData, Status) {


$("#WSOutput").html("").append("<b>This is the output from the GetListItems operation:</b>");
$(xData.responseXML).find("z\\:row").each(function() {

$("#WSOutput").append("<li>" + $(this).attr("ows_Course_x0020_Name") +
" " + $(this).attr("ows_Course_x0020_Outline") + " " +
$(this).attr("ows_Code") + " " + $(this).attr("ows_Attachments") + "</li>");

});

$("#WSOutput").append(replaceTags(xData.responseXML.xml));

}

});

});

</script>
</
head>
<
body
>
<
div
id="WSOutput"></div>
<
hr/>
<
div
id="debugDiv1"
style="height:60%;width:50%;overflow-y:auto; overflow-x:hidden" />
</
body>