Showing posts with label SpServices. Show all posts
Showing posts with label SpServices. Show all posts

Wednesday, 4 February 2015

get items from sharepoint list using spservices

1.Create a Custom List Name as "Emp" and Create a below Column Name

  FirstName - Single Line Text
  LastName-Single Line Text
  Location-Single Line Text

2.Create one Content Editor WebPart and  paste the below code

<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js"></script>

<script type="text/javascript">
 $(document).ready(function() {
   GetEmpListItemData();
});  
function GetEmpListItemData() {
   
    // get Emp list data
    var datarows = [];
    $().SPServices({
        operation: "GetListItems",
        webURL:"https://Site Collection Url/sites/TestSite",
        async: false,
        listName: "Emp",
       CAMLViewFields: "<ViewFields><FieldRef Name='Title'/><FieldRef Name='FirstName'/><FieldRef Name='LastName'/><FieldRef Name = 'Location'/></ViewFields>",
        CAMLQuery: "<Query><OrderBy><FieldRef Name='ID' Ascending='True'/></OrderBy></Query>",
        completefunc: function(xData, Status) {
            var listitemrows = $(xData.responseXML).find("z\\:row, row");
            $(listitemrows).each(function() {
                 var  Id = $(this).attr("ows_ID");
                 var  Title = $(this).attr("ows_Title");              
                 var  FirstName = $(this).attr("ows_FirstName");
                 var  LastName = $(this).attr("ows_LastName");
                 var  Location =  $(this).attr("ows_Location");                
                 datarows.push({Id: Id, Title: Title,FirstName: FirstName,LastName: LastName,Location: Location});                
            });
        }

    });

  var myJsonString = JSON.stringify(datarows);
        alert(myJsonString);
for (var arrayIndex in datarows) {    
       var Id=datarows[arrayIndex].Id;
           alert(Id);
         }    
}

</script>

Continue Reading...

check current logged user in sharepoint group using spservices

<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>


<script type="text/javascript">
 $(document).ready(function() {

   $().SPServices({
     operation: "GetGroupCollectionFromUser",
     userLoginName: $().SPServices.SPGetCurrentUser(),
     async: false, 
     completefunc: function(xData, Status) {
        if($(xData.responseXML).find("Group[Name='TestGroup']").length == 1)
        {
            alert("Yes");
        }
        else
       {
           alert("No");
       }
      }
   });
}); 
</script>
Continue Reading...

Monday, 2 February 2015

Get current logged user details in SharePoint using spservices

 1.Create one Content Editor WebPart and  paste the below code

<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>

<script type="text/javascript">

$(document).ready(function() { 

 GetLoggeduserInfo();
   
});

function GetLoggeduserInfo()
{

$().SPServices({
    operation: "GetUserInfo",
    async: false,
    userLoginName: $().SPServices.SPGetCurrentUser(),
    completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
            curUserId = $(this).attr("ID");
            curUserName = $(this).attr("Name");
            curFullUserName = $(this).attr("ID")+";#"+$(this).attr("Name");
            alert(curFullUserName);
        });
    }
});
}

</script>
Continue Reading...

SharePoint Modal dialog box using spservices

<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>


<div style="padding:10px;text-align:center;cursor:pointer;">
<a href="javascript:;" onclick="ModelPopFn();">
<img src="/sites/TestSite/Style%20Library/Samples/Image1.jpg"/>
</a>
</div>

<script>
function ModelPopFn()
{
var EmpListFormUrl = "/sites/TestSite/Lists/Emp/NewForm.aspx";
openmodaldialog(EmpListFormUrl);

}
function openmodaldialog(href)
{
var options = {
url: href,
title: "Create a new Emp Details",
allowMaximize: true,
showClose: true,
width: 750,
height: 450,
dialogReturnValueCallback: function(dialogResult)
        {
        window.location.href=window.location.href;
        }
}
SP.UI.ModalDialog.showModalDialog(options);
}
</script>

Continue Reading...

get item from sharepoint list using spservices

1.Create a Custom List Name as "Emp" and Create a below Column Name

  FirstName - Single Line Text
  LastName-Single Line Text
  Location-Single Line Text

2.Create one Content Editor WebPart and  paste the below code
 
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style Library/Samples/jquery.SPServices-2014.02.min.js"></script>
<script type="text/javascript" src="https://Site Collection Url/sites/TestSite/Style%20Library/Samples/jquery.dataTables.min.js"></script>


<style>

<style type="text/css">
.myOtherTable { background-color:#FFFFE0;border-collapse:collapse;color:#000;font-size:18px; }
.myOtherTable th { background-color:#BDB76B;color:white;width:32%; }
.myOtherTable td, .myOtherTable th { padding:5px;border:0; }
.myOtherTable td { border-bottom:1px dotted #BDB76B; }

</style>


<script type="text/javascript">

$(document).ready(function() {

 EmpDataBind();
  
});
var sFullHtml = '';
                                     
             function EmpDataBind() {
                                                        
       
    sFullHtml += '<table id="TblEmpInfo" class="myOtherTable" >';
sFullHtml += ' <tr >';
sFullHtml += ' <th>First Name</th>';
sFullHtml += ' <th>Last Name</th>';
sFullHtml += ' <th>Location</th>';
sFullHtml += ' </tr>';
     
             
try
                            {
                           
                             $().SPServices({
                            
operation: "GetListItems",
async: false,
  listName: "Emp",
            CAMLQuery: "<Query><OrderBy><FieldRef Name='ID' Ascending='True'/></OrderBy></Query>",
            CAMLViewFields: "<ViewFields><FieldRef Name='Title'/><FieldRef Name='FirstName'/><FieldRef Name='LastName'/><FieldRef Name = 'Location'/></ViewFields>",  
                    
  completefunc: function (xData, Status) {

    
       $(xData.responseXML).SPFilterNode("z:row").each(function() {
       
          var Title = ($(this).attr("ows_Title"));
         
          var FirstName = ($(this).attr("ows_FirstName"));
         
          var LastName = ($(this).attr("ows_LastName"));
      
          var Location = ($(this).attr("ows_Location"));
       
sFullHtml += '<tr>';

                    sFullHtml += '<td align="left" valign="top">'+ FirstName +'</td>';
                    sFullHtml += '<td align="left" valign="top">'+ LastName  +'</td>';
                    sFullHtml += '<td align="left" valign="top">'+ Location  +'</td>';

sFullHtml += '</tr>';


       
});
   }        
});

}catch(err){}


sFullHtml += '</table>';



  $(".EmpInfo").html(sFullHtml);

        }


        function OnLoadFailed(sender, args) {
       
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
       
</script>


<div class="EmpInfo" style="margin-top:10px;">
</div>

output:-



Continue Reading...

Followers

Follow The Author