Posts

Showing posts from August, 2016

Get Current Login User Details using Rest API in SharePoint 2013

//Below code will get the current user id from the Site var currentUserID = _spPageContextInfo.userId; //this function get the user details from current user id $(document).ready(function() { var success = getUser(currentUserID); alert(success ); }); function getUser(id){ var deferred = $.Deferred(); var serverUrl = _spPageContextInfo.webAbsoluteUrl; var ListNameUrl = String.format( "{0}/_api/Web/GetUserById(" + id + ")",serverUrl); jQuery.ajax({ url: ListNameUrl, type: "GET", headers: { "Accept": "application/json;odata=verbose" }, success: function(data) { var dataResults = data.d; //get login name   var loginName  = dataResults.LoginName.split('|')[1]; alert(loginName);      //get display name displayName = dataResults.Title; deferred.resolve(); } }); return deferred.promise(); }

Get query string from javascript

By using the below code we can get the query string value & we can pass it to new URL. var QuerystringID = getParameterByName("ID"); if ( QuerystringID  != "") { window.location = "<NewUrl>?DID="+ QuerystringID ; } //below function get the query string value from URL function getParameterByName(name)  { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); }

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

Image
Upload  Single/Multiple  file by using the REST API and jQuery SharePoint 2013 Here you can find how to upload single/multiple file in SharePoint 2013 Library using Rest API. We can use the Content Editor web part to call the script files. Include Script files in Content Editor: Go to content editor -> Edit Source -> enter the code like below (code for including the script files) For 'jquery.min.js' we can either use direct link from online or we can download to our SharePoint library & We can use that. <script src=" https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> OR use the below code <script src="/ sites/<SiteName>/<Subsite>/SiteAssets/jquery-1.11.1.min.j s"></script> <script src="/ sites/ <SiteName>/<Subsite> /SiteAssets/taskpage.js " type="text/javascript"></script> <script src=" /sites/ <SiteName>/<Subs

People Picker Get using sp.js & Update(Single User & Multi User) using REST API IN SHAREPOINT 2013

Image
When you try to create/update list item just check the fields details of the list using the REST API. for an example I have created a List named  TestList . Following is the field details: Title:  Text TestColumn1:  Text Text Column 2:  Text Test Column 3:  People and Group Now to check the field details and check the details of the fields using the following REST API URL: http : //SITEURL/_vti_bin/client.svc/web/lists/getByTitle('TestList')/items Now you will get following data in IE Or Chrome:  Find your column name from the XML page. Now check the above picture carefully, the userid needs to be saved in the  TestColumn3Id  column not in the  TestColumn3 . Now check the following code: Go To  SiteAssets  and & Add jquery-1.11.1.min.js and TestScript.js. Add the following code in the Scripts.js file Open any page & Insert content editor webpart. Include the below code in Content Editor. //Code for content editor: <script src=&q