Posts

Showing posts with the label JSOM

Enable SharePoint Read only columns of List/Library

Image
Enable SharePoint Read only columns of List/Library Some times under SharePoint List/Library settings columns are not enabled(Greyed out) to edit or delete. Using below jsom code we can enable the readonly columns. For this you need to proide below inputs 1.List Name 2.ContentType ID whitch the column is associated 3.Any substring of column name (example: If column name is 'Country Name' -> you can type 'Country') Here we can get the content type id from list settings if we click content type from URL we can get content type ID We need to add Script editor web part & insert the below code. < html > AnySubStringofColumnName: < input type = "text" id = "txtColName" />< br />< br /> ListName: < input type = "text" id = "txtListName" />< br />< br /> ContentTypeID: < input type = "text" id = "txtContentType" />< br />< ...

Deploy SharePoint workflows to SharePoint List/Library using JSOM

     Below code will deploy the workflow into SharePoint list/library. We need to use workflow definition id to deploy the workflow.      First function will get the workflow definition id based on the given workflow name & we will pass the workflow definition id to 2nd function to deploy into list/library. (Note this will return only 2013 workflows) //add the following workflowservices js files in document.ready function(as mentioned below) Or you can mentioned in your HTML file also. $(document).ready(function() { //load workflow js files SP.SOD.executeFunc(' sp.js ', ' SP.ClientContext' , function(){ SP.SOD.registerSod(' sp.workflowservices.js ', SP.Utilities.Utility.getLayoutsPageUrl(' sp.workflowservices.js ')); SP.SOD.executeFunc(' sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager" ); }); }); //give your existing workflow name, list/library name, new name for workflow var existingWor...

Change default content type of SharePoint List/Library using JSOM (JavaScript)

Below code will change the default content type of the List/Library. It will reverse the order of available content types in the List. So our recently added content type will set into default content type. var listName = " Your List/Library name to change default content type " //Change default contend type (this code will reverse the current content type order, so our recently added content type will come first) function setAsDefaultContentType(listName) { var  c = SP.ClientContext.get_current(); var  folder = c.get_web().get_lists().getByTitle(listName).get_rootFolder(); c.load(folder, ' ContentTypeOrder '); c.executeQueryAsync( function () {  folder.set_uniqueContentTypeOrder(folder.get_contentTypeOrder().reverse());  folder.update();  c.executeQueryAsync( function  onSuccess()   { alert(' Content type changed!!! ');   },    function onFail()    ...

Ajax Loader

Image
To display loading symbol while ajax call, you can use the below code. Content Editor Code: <link href=" https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css " rel="stylesheet"/> <script src=" https://code.jquery.com/jquery-1.10.2.js "></script> <script src=" https://code.jquery.com/ui/1.10.4/jquery-ui.js "></script> <link href="/sites/<sitename>/SiteAssets/CSS/Style.css" rel="stylesheet" type="text/css"/> <script src=" /sites/<sitename> /SiteAssets/Scripts/Test.js"></script>   <div class="modal" id="modalDiv">&#160;</div> Style.css Code: .modal {     display:    none;     position:   fixed;     z-index:    1000;     top:        0;     left:       0;     height:...

People Picker getting user by sppeoplepicker.min.js & updating (Single & Multi User) using REST API IN SHAREPOINT 2013

Image
Add a list item with People Picker (Single User & Multi User) Using REST API IN SHAREPOINT 2013 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 , sppeoplepicker.min.js  & TestScript.js....

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...