Tuesday, July 17, 2012

SPServices-Jquery

To Create a List :
$().SPServices({

operation: "AddList",




listName: "Test List by SPServices",

description: "List with lots of columns",

templateID: "100", // Custom list

completefunc: function (xData, Status) {

alert(xData.responseText);

}

});

To Delete a List:
$().SPServices({
operation: "DeleteList",
listName: "Complicated List",
completefunc: function (xData, Status) {
alert(xData.responseText);
}
});
To get the ID of last created list item: SPGetLastItemId
var lastId = $().SPServices.SPGetLastItemId({
listName: "feedback"
});
alert(lastId)
SPRedirectWithID:
$(document).ready(function() {
$().SPServices.SPRedirectWithID({
redirectUrl: "DispForm.aspx",
qsParamName: "OrderID"
});
});
GetListItems:
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "feedback",
//CAMLViewFields: "<ViewFields Properties='True' />",
CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>",
//CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Message' /></ViewFields>",
completefunc: function(xData, Status) {
var table='<table>';
table+="<tr><td>Name</td>";
table+="<td>Message</td></tr>";
//alert(xData.responseText);
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var $node = $(this).attr('ows_Title');
var $msg = $(this).attr('ows_Message');
table+="<tr><td>"+$node+"</td>";
table+="<td>"+$msg+"</td></tr>";
});
table+="</table>";
$('#tasks').html(table);
}
});
});
getting the MetaInfo in a useful way. The trick is to add
CAMLViewFields: "<ViewFields Properties='True' />",
CAMLQueryOptions: "<QueryOptions><ExpandUserField>True</ExpandUserField></QueryOptions>"
returns account name, email, and name instead of just the name.
Function:$().SPServices.SPGetLastItemId
Functionality
Function to return the ID of the last item created on a list by a specific user. Useful for maintaining parent/child relationships. This function was built for use by the $().SPServices.SPRedirectWithID function, but is also useful in other circumstances.
Prerequisites
None
Syntax
$().SPServices.SPGetLastItemId({
webURL: "",
listName: "",
userAccount: "",
CAMLQuery: ""
});
webURL
The URL of the Web (site) which contains the listName. If not specified, the current site is used. Examples would be: "/", "/Accounting", "/Departments/HR", etc. Note: It's always best to use relative URLs.
listName
The name or GUID of the list. If you choose to use the GUID, it should look like: "{E73FEA09-CF8F-4B30-88C7-6FA996EE1706}". Note also that if you use the GUID, you do not need to specify the relationshipWebURL if the list is in another site.
userAccount
The account for the user in DOMAIN\username format. If not specified, the current user is used.
CAMLQuery
The CAMLQuery option allows you to specify an additional filter on the relationshipList. The additional filter will be <And>ed with the existing CAML which is checking for matching items based on the parentColumn selection. Bacause it is combined with the CAML required to make the function work, CAMLQuery here should contain a CAML
fragment such as:
CAMLQuery: "<Eq><FieldRef Name='Status'/><Value Type='Text'>Active</Value></Eq>"
Example
The following example will return the most recently created item's ID for the current user from the States list in the current site.
<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.4.1.min.js"></script>
<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery.SPServices-0.5.1.min.js"></script>
<script language="javascript" type="text/javascript">
var lastId = $().SPServices.SPGetLastItemId({
listName: "States"
});
</script>
Function:$().SPServices.SPListNameFromUrl
Functionality
This utility function, which is also publicly available, returns the current list's GUID *if* called in the context of a list, meaning that the URL is within the list, like /DocLib or /Lists/ListName.
Syntax
$().SPServices.SPListNameFromUrl();
Example
var thisList = $().SPServices.SPListNameFromUrl();
Function
$().SPServices.SPGetStaticFromDisplay
Functionality
This function returns the StaticName for a column based on the DisplayName. This simple utility function, which utilizes the GetList operation of the Lists Web Service, seemed useful to expose as a public function.
Prerequisites
None
Syntax
var thisStaticName = $().SPServices.SPGetStaticFromDisplay ({
webURL: "",
listName: "",
columnDisplayName: ""
});
webURL
The URL of the Web (site) which contains the listName. If not specified, the current site is used. Examples would be: "/", "/Accounting", "/Departments/HR", etc. Note: It's always best to use relative URLs.
listName
The name or GUID of the list. If you choose to use the GUID, it should look like: "{E73FEA09-CF8F-4B30-88C7-6FA996EE1706}". Note also that if you use the GUID, you do not need to specify the relationshipWebURL if the list is in another site.
columnDisplayName
The
DisplayName of the column
Example
The following example will return the StaticName for the Title column in the States list in the current site.
<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery.SPServices-0.5.4.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var thisStaticName = $().SPServices.SPGetStaticFromDisplay ({
listName: "States",
columnDisplayName: "Title"
});
alert("The StaticName for the Title column is: " + thisStaticName);
... do more stuff...
});
</script>
Function
$().SPServices
Web Service
Forms
Supported Operations
Operation
Options
MSDN Documentation
Introduced
GetForm
[webURL], listName, formUrl
GetFormCollection
[webURL], listName
Note that GetFormCollection will list all forms for the list, not just the three EditForm, DispForm, and NewForm shown in the MSDN example. It will get custom forms too. Not just those set as default.

$().SPServices({
operation: "GetFormCollection",
webURL: '/[sitepath]/',
listName: '[list name]',
completefunc: function(xData, Status) {
alert( xData.responseText );
$(xData.responseXML).find("Forms > Form").each(function() {
var $node = $(this);
console.log( $node.attr("Url") );
});
}
});

No comments:

Post a Comment