Posts

Showing posts from July, 2020

How to get fields of enterprise Task/Project/Resource of SharePoint in JSOM or JavaScript?

Get field of enterprise Task/Project/Resource of SharePoint in JSOM or JavaScript: Use the below snippet all fields/column of Task using JSOM. <script type="text/javascript" src="_layouts/15/sp.js"></script> <script type="text/javascript" src="_layouts/15/ps.js"> </script> <script type="text/javascript" > var Fields = []; function getFields (from, type) {     // console.log(type);     console.log('Getting all fields');     // Initialize the current client context.      var filcontext = PS.ProjectContext.get_current();     var allFields = filcontext.get_customFields();     filcontext.load(allFields, "Include(Id, Name, EntityType, InternalName, FieldType, Formula)");     filcontext.executeQueryAsync(OnRequestSuccess, OnRequestFailed);     // Callback for request failure     function OnRequestFailed (sender, args) {         console.log(args.get_...

How to get Task Name, Task Id and Outline from enterprise Project using JSOM?

Get Task Name, Task Id and Outline from enterprise Project using JSOM: Use the below snippet to get Task Name, Task Id and Outline from a Project Using JavaScript. <script type="text/javascript" src="_layouts/15/sp.js"></script> <script type="text/javascript" src="_layouts/15/ps.js"> <script type="text/javascript" > var projectId = "8551cf46-2695-ea11-k085-00155dac4e02" fetchTaskfromProjectSchedule(projectId) function fetchTaskfromProjectSchedule(projGuid){     // Get Task Collection     var context = PS.ProjectContext.get_current();     var project = projects.getByGuid(projGuid);     var tasks = project.get_tasks()     context.load(tasks);     context.executeQueryAsync(function(){                  // Tasks Collection succefully retrieved         var enumerator = tasks.getEnumerator();         while (enumerator.moveNex...

Get Current Web Logged In User of SharePoint Site in jQuery

Get Current web logged in User of a SharePoint site in jQuery: Use the below snippet and just replace the jQuery library URL and run on you SharePoint page. <script src="../Assets/Jquery/jquery-1.9.1.min.js"></script> <script > function getCurrentLogInUser(){ $.ajax({     url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/currentuser",     type: "GET",     async:false,     headers: { "Accept": "application/json;odata=verbose" } }).success(function( data ){     console.log( data );     console.log( data.d.Title ); }).error(function(e){     console.log( e ); }); } getCurrentLogInUser(); </script> Output:

Get Current Web User of SharePoint with JavaScript

Image
Get Current Web User of SharePoint with JavaScript: Use the below code to get current logged in User details of a SP Site: <script type="text/javascript" src="_layouts/15/ps.js"></script> <script type="text/javascript"> function getAvailableUserInfo(){       //Get the Project context for this web       var projContext = PS.ProjectContext.get_current();       var user = projContext.get_web().get_currentUser();       projContext.load(user);       projContext.executeQueryAsync(function () {         console.log("Current Logged in User is " + user.get_title());         console.log("Id of Current Logged in User is " + user.get_id());         console.log("Login Name of Current Logged in User is " + user.get_loginName());         console.log("Email of Current Logged in User is " + user.get_email());       }, ...

Get Current SharePoint Web User using JavaScript

Get Current SharePoint Web User using JavaScript: Use the below snippet code to get current logged in User <script type="text/javascript" src="_layouts/15/sp.js"></script> <script type="text/javascript" > function getInfoOfCurrentUser(){    var context = new SP.ClientContext.get_current();    var web = context.get_web();      var currentUser = web.get_currentUser();    context.load(web);    context.executeQueryAsync(       function(){ //On success function         var userName = currentUser.get_title();         var id = currentUser.get_id();         var email = currentUser.get_email();         var loginName = currentUser.get_loginName();         console.log(userName);         console.log(id);         console.log(email);         console.lo...

How to get all choice values from choice field from a SharePoint List using REST API?

Get all choice values from choice field from a SharePoint List using REST API: Here we going to get all values of a choice field "Country" (Normal Field Not lookup) from SharePoint List Students. End point "/_api/web/lists/getbytitle('Students')/Fields" gives all the fields details. We are here filtering the Country Field by Title Name (We may also use its internal name) and then calling. Then Using getJSON method we are fetching the values from Country. $.getJSON(_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Students')/Fields?$filter=Title eq 'Country'", function(res) {           var allChoices = res.value[0].Choices;           console.log(allChoices);  }); OR,   $.ajax({         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle(' Students ')/Fields?$filter=InternalName eq ' Country0 '",         dataType: 'json',       ...

"Access denied. You do not have permission to perform this action or access this resource."

SharePoint REST Error: "Access denied. You do not have permission to perform this action or access this resource." Cause-As you are calling the REST API request without logged in on SharePoint Online. Or You have limited permission to access the required resource. Solution: If you are not in on SharePoint then Logged in then problem will get resolved. Or If you have limited user permission then you need to ask access permission to the System Admin/SharePoint Admin. After getting permission your problem will be resolved.

How to fetch data from a look up field of SharePoint List using REST API in jquery?

Image
 Fetch data from a look up field of SharePoint List using REST API: Using below code we are able to fetch data from the lookup field. Events//SharePoint list Name Program is Lookup field, Its internal name is Program in Events list. Program is lookup from another field of another list where its internal name Title. To fetch the data from look up field we need to add Program/Title in $select and $expand   var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Events')/items?$select=*,Program/Title&$expand=Program/Title";//replace list Name (Events) and try in the console of browser $.ajax({   url:url,     method:"GET",     headers: { "accept": "application/json;odata=verbose", //It defines the Data format      "content-type": "application/json;odata=verbose" //It defines the content type as JSON      },     success:function(response){         console.log...

How delete all Items of SharePoint List using REST API?

Delete all Items of SharePoint List using REST API: . Use the below code to delete items of list more than 5000 items at time. var listname = "Company";//SharePoint list Name var resultData = []; // variable (array) is used for storing list items var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('"+listname+"')/items?$top=5000"; //SP list URL or REST API; function fetchDataFromSPList(){     $.ajax({         url: url,           method: "GET",           headers: {               "Accept": "application/json; odata=verbose"           },         success: function(data){             resultData = resultData.concat(data.d.results);             if (data.d.__next != undefined) {             ...

How to fetch data more than 5000 from SharePoint list using rest api in jquery?

Image
Fetch more than 5,000 items from SharePoint using rest api: var resultData = []; // variable (array) is used for storing list items var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Company')/items?$top=1000"; //SP list URL or REST API, In rest api Company is List name function fetchDataFromSPList(){     $.ajax({  // Ajax          url: url,           method: "GET",           headers: {               "Accept": "application/json; odata=verbose"           },         success: function(data){             resultData = resultData.concat(data.d.results);             if (data.d.__next != undefined) {                 url = data.d.__next;           ...