Monday, 3 September 2012

SP Services (GetListItems , UpdateListItems )


var cid = JSRequest.QueryString["ID"];

<script type="text/javascript" src="../js/jquery-1.4.2.min.js" ></script>
<script type="text/javascript" src="../js/jquery.SPServices-0.6.2.min.js" ></script>

<a href="javascript:void(0);"  onclick="javascript:GetListItems('3');" id="href1" >
Get List Item by Id</a>

<a href="javascript:void(0);"  onclick="javascript:CreateNewItem($('#txtdn').val());" id="href2" >
Insert New Item</a><br/>
     
 <script type="text/javascript">
----------------Get list item-------------------
 function GetListItems(ID)
{
 var CamlQuery = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ID + "</Value></Eq></Where></Query>";
         var CamlViewFields = "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /></ViewFields>";
         // this let me know that the function is getting called and passed the correct parameter value
         alert('function called and passed last ID of : ' + ID);

$().SPServices({
   operation: "GetListItems",
   async: false,
   listName: "DomainName",
   CAMLViewFields: CamlViewFields,
   CAMLQuery: CamlQuery,
     completefunc: function (xData, Status) {
       $(xData.responseXML).find("[nodeName='z:row']").each(function() {

       // just load a new variable with the returned value      
       var thisID = $(this).attr("ows_Title");
       alert(thisID);

     });
   }
         });
       }
 ---------------- //Add new item in list--------------
 
   function CreateNewItem(title) {
   alert(title);
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "DomainName",
        valuepairs: [["Title", title]],
        completefunc: function(xData, Status) {
          alert("completed");
        }
    });
}

---------------- //Update new item in list--------------

</script>



No comments:

Post a Comment