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

Saturday, January 23, 2021

Sort Order of a Lookup Column in SharePoint?

In this article ,  sort my lookup column based on a column 

 <script type="text/javascript" language="javascript">

    $().SPServices.SPFilterDropdown({ //This is the function that does the sorting.

        relationshipList: "Code", //This is the name of the lookup field in the form.

        relationshipListColumn: "Title", //This is the original column name from the lookup list as SharePoint knows it.

        relationshipListSortColumn: "Sortby"

        columnName: "Code", //This is the column name in the lookup list as it shows up.

        CAMLQuery: "<Neq><FieldRef Name='Title'/><Value Type='Text'></Value></Neq>", //This is the CAML Query if you want to select a specific set of items from the list. In this example it doesn't select items where the Title column is null. Note, the Title column is the original column name.

        debug: true

    });

</script>

Wednesday, August 10, 2016

jQuery SPServices get list guid

$().SPServices({
operation: "GetList",
listName: "GSMHelp",
async: false,
completefunc: function (xData, Status) {
alert($(xData.responseXML).find("List").attr("ID"));
}
});

Friday, August 5, 2016

SharePoint 2013 get current user using JavaScript

<script src="/SiteAssets/jquery.SPServices-2013.02a.js" type="text/javascript"></script>
<script src="/SiteAssets/jquery.js" type="text/javascript"></script>

<script type="text/javascript">
  var userid= _spPageContextInfo.userId;
  var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
  var requestHeaders = { "accept" : "application/json;odata=verbose" };
  $.ajax({
    url : requestUri,
    contentType : "application/json;odata=verbose",
    headers : requestHeaders,
    success : onSuccess,
    error : onError
  });

  function onSuccess(data, request){
    var loginName = data.d.Title;
    alert(loginName);
  }

  function onError(error) {
    alert("error");
  }
</script>

Friday, May 20, 2016

SharePoint Site Collection Administrators : Jquery

var user = SP.ClientContext.get_web().get_currentUser();

var value = user.get_isSiteAdmin ();
SPServices:

$().SPServices({
   operation: "GetUserInfo",
   userLoginName: $().SPServices.SPGetCurrentUser(),
   completefunc: function(xData, Status) {
   console.log$(xData.responseXML).find("User").attr("IsSiteAdmin"))
   }
});

how to get current sharePoint user department using javascript/spservices

<script src="/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>  
<script src="/Scripts/jquery.SPServices-2014.02.min.js" type="text/javascript"></script>  
<script language="javascript" type="text/javascript" src="/Scripts/jquery.SPServices-0.7.2.min.js"></script>

<script language="javascript" type="text/javascript" src="/Scripts/sputility.min.js"></script>


<script type="text/javascript">  

$(document).ready(function() {  
    // get the title of current user  
    var UserName= $().SPServices.SPGetCurrentUser({  
    fieldName: "Title",  
   debug: false  
});  
// get department of current user
var userDepartment = $().SPServices.SPGetCurrentUser({
   fieldName: "Department"
   });
   




});  

</script>

Wednesday, March 2, 2016

How to retrieving next 7 Days Due Date Tasks from SharePoint List

C# Coding:


DateTime strdate = (DateTime)DateTime.Today.AddDays(7);
            string strgetDate = strdate.Year + "-" + strdate.Month + "-" + strdate.Date.Day;

SPWeb currentWeb = SPContext.Current.Web;
            SPList lst = currentWeb.Lists["Projects"];
            SPQuery sQuery = new SPQuery();
            sQuery.Query = "<Where><Geq><FieldRef Name='DueDate' /><Value Type='DateTime'>"+strgetDate+"</Value></Geq></Where><OrderBy><FieldRef Name='DueDate' /></OrderBy>";
            SPListItemCollection myColl = lst.GetItems(sQuery);
            if (myColl.Count > 0)
            {
                grdBind.DataSource = myColl.GetDataTable();
                grdBind.DataBind();
            }

Batch Command Update for Insert the records into a SharePoint list

var query = "<Batch OnError='Continue' RootFolder='" + RootFolder + "' ViewName=''>";

for (var i = 0; i < data.length - 1; i++)
{

 query += "<Method ID='1' Cmd='New'>";
        query += "<Field Name='Title'>" + DocTitle;
        query += "</Field>";
        query += "<Field Name='GrpTitle'>" + GrpTitle;
        query += "</Field>";
        query += "<Field Name='Category'>" + catID;
        query += "</Field>";
        query += "<Field Name='SubCat'>" + subCategory[i];
        query += "</Field>";
        query += "<Field Name='DispOrder'>" + DispOrder;
        query += "</Field>";
        query += "<Field Name='DocID'>" + DocID;
        query += "</Field>";
        query += "<Field Name='DocURL'>" + DocURL;
        query += "</Field>";
        query += "<Field Name='DocDesc'>" + DocDesc;
        query += "</Field>";
        query += "<Field Name='DocType'>" + DocType;
        query += "</Field>";
        query += "</Method>";

}
 query += "</Batch>";
var resf = oLists.updateListItems("lstDocOrder", query);

$().SPServices.SPArrangeChoices not working in SPServices

Its working fine
Please download lastest version 2014
https://spservices.codeplex.com/


<script type="text/javascript">

$(document).ready(function() {

$().SPServices.SPArrangeChoices({
columnName: "Research Fee Received",
perRow: 2
});

});</script>

Friday, February 12, 2016

How to update bulk items and all items in custom list using SPServices

In this article,bulk updatein sharepoint list
 <input id="btnUpdateItem" type="button" value="Delete all items" />
jQuery:
$('#btnUpdateItem').click(function()
{
UpdateAction();
});
function UpdateAction()
{
$().SPServices.SPUpdateMultipleListItems({
  listName: "SupportTable-OLEMData",
  CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query>",
  valuepairs: [["Status", "Inactive"]]
});
alert("All items are updated!");
}

How to delete bulk items and all items in custom list using SPServices

<input id="btnDeleteItem" type="button" value="Delete all items" />


$('#btnDeleteItem').click(function()
{


DeleteAction();

});


function DeleteAction()
{
$().SPServices.SPUpdateMultipleListItems({
  listName: "SupportTable-OLEMData",
  CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query>",
  batchCmd: "Delete"
});
alert("All items are deleted!");
}

Friday, February 5, 2016

How to get GetAllSubWebCollection or all site collection using SPServices ?

  $().SPServices({
        operation: "GetAllSubWebCollection",
        async:false,
        completefunc: function(xData, Status) {
            $(xData.responseXML).find("Webs > Web").each(function() {
              
                var $node = $(this);
                var siteTitle = $node.attr("Title").replace(/\s/g, "");
                
                alert(siteTitle);
            });
            }
        }); 

Wednesday, December 23, 2015

Advantages of SPServices?


  1. Allows anonymous access
  2. SharePoint functionality is exposed with the SOAP Web Services,
  3. Works cross-site and cross-domain 
  4. Client side coding
  5. Familer to any other platform like javascript,jQuery angular JS
  6.  assuming that the authentication model you are using allows it
  7.  Simply pass the required parameters to the Web Service operation,
  8. Built on top of jQuery, which is very good at ensuring cross-browser compatibility
  9. Regularly updated and refined to be compatible with new versions of jQuery and to add new functionality based on user input
  10. Works identically in SharePoint 2007 and 2010 

How to get all fields from sharepoint list in SPServices CAMLViewFields

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

$().SPServices({
operation: "GetListItems",
async: false,
listName: "Employee",
CAMLViewFields: "<ViewFields Properties='True' />",

completefunc: function (xData, Status) {
$(xData.responseXML).find("[nodeName='z:row']").each(function () {
alert($(this).attr("ows_TotalHours"));
});
}
});

Uncaught TypeError: $(...).SPServices is not a function

Uncaught TypeError: $(...).SPServices is not a function


Please add SPServices referece file and Jquery min file

Please download script file below link.
https://spservices.codeplex.com/releases/view/119578

http://code.jquery.com/jquery-2.1.4.min.js

Saturday, December 12, 2015

Date Field update using SPServices?

In this below script,Date Field update using SPServices

Date Field update using SPServices In SharePoint
 var dueDateVal = new Date().toISOString();
This is date format in Sharepoint
     $().SPServices({
        operation: "UpdateListItems",
        async: false,
        listName: "Paid Check",
         batchCmd: "Update",
         ID:id,
        valuepairs: [["Status","Completed"],["Completed_x0020_on",dueDateVal],["WF_Run",1]],
         completefunc: function(xData, Status) {
       
                         }
    });

Wednesday, December 9, 2015

How to get User Information using SPServices?

In this below script, get User Information using SPServices, JQuery, Javascript and html

get User Information using SPServices
$().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");
        });
    }
});

Thursday, November 5, 2015

How to get login user display Name in SPServices?

var loginname=$().SPServices.SPGetCurrentUser({

  fieldName: "Title",
  fieldNames: {},    
  debug: false
});

Thursday, October 29, 2015

how to update Choice column in SharePoint list using SPServices?

$().SPServices({
        operation: "UpdateListItems",
        listName: "businesscard",
        async: false,
  ID:selectid,
   batchCmd: "Update",
   valuepairs: [["dStatus", "Ordered"]],
        completefunc: function (xData, status) {
         $(xData.responseXML).SPFilterNode("z:row").each(function() {
       
      alert("sucess");
       
        });
        }
        });


<select id='ddlstatus'><option>Approved</option><option>Completed</option></select>

Wednesday, October 28, 2015

How to get user information using SharePoint SPServices/Webservices

 We have access to account IDs.
For Example:

var userId=12;

No access to user names.



var userId=12;
$().SPServices({
     operation: "GetListItems",
     listName: "User Information List",
     CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + userId + "</Value></Eq></Where></Query>",
     CAMLRowLimit: 1,
     completefunc: function (xData, Status) {
         var userDetail = {};
         var row = $(xData.responseXML).SPFilterNode("z:row").get(0);
         userDetail .Name = $(row).attr("ows_Name");
         userDetail .Title = $(row).attr("ows_Title");
         userDetail .Email = $(row).attr("ows_Email");
         result(userDetail );
     }
  });

How to get login user id using SPServices

<script>
$().SPServices({
operation: "GetUserProfileByName",
async: false,
AccountName: $().SPServices.SPGetCurrentUser(),
completefunc: function (xData, Status) {
$(xData.responseXML).find("PropertyData > Name:contains('Name')").each(function() {
Name = $(this).parent().find("Values").text();
alert(Name);
});
}
});
  });
  </script>
In this code we have get all user details propertyData.
$(xData.responseXML).find("PropertyData > Name:contains('Name')").each(function() {
Name = $(this).parent().find("Values").text();
alert(Name);
});