Skip to main content

Posts

Showing posts with the label JSOM

How to check which permission user have on the list.

In this blog, we are going to learn how to check the permission of the user on the list. Some times we need to show and hide several things as per the permission assigned to the user. SharePoint has different permission levels. We are using the function of "sp.js", to use function of sp.js we need to include the sp.js file. In this example, we are checking for the delete permission. SP . SOD.executeFunc('sp.js', 'SP.ClientContext', function () {      checkPermssion(); }); function checkPermssion(){ var web,clientContext,currentUser,oList; clientContext = new SP.ClientContext.get_current(); web = clientContext.get_web(); currentUser = web.get_currentUser();     oList = web.get_lists().getByTitle(' List Title');  clientContext.load(oList,'EffectiveBasePermissions');  clientContext.load(currentUser);   clientContext.load(web);             clientContext.executeQueryAsync(function(){  if (oList....

Retrieve List Items using JSOM.

To return or get items from the list you have two options if you want to retrieve the single item you can use the GetItemById() method or for multiple items use GetItems(CamlQuery). Replace the siteUrl with your siteUrl for example ("xyz.sharepoint.com") and TitleOfList with your title list from which you want to get the items. Code to get the list item using the ID.  function getListiem(){ var context = new SP.ClientContext(siteUrl);  var list = context.get_web().get_lists().getByTitle('TitleOfList');  var targetListItem = list.getItemById(listItemID); context.load(targetListItem); context.executeQueryAsync(onGettingRecord, onFailedCallback); } function onGettingRecord(){ alert(targetListItem.get_item('Title')); } function onFailedCallback(sender,args){ alert('Request failed. ' + args.get_message() + '\n'+args.get_stackTrace()); } Code to get multiple items from the list. function getItems(){ var...

Update SharePoint list item using JSOM.

In this blog, we are going to learn how to update the SharePoint list item using the JSOM. To update the SharePoint list item or delete it, we can do this using the help of item id. Here we are performing an operation on the list named "Info", which have two columns "Name" and "Address".  Replace "***.sharepoint.com" with your tenant URL and replace the ListItemID with your item id. var clientContext = new SP.ClientContext('***.sharepoint.com'); var oList = clientContext.get_web().get_lists().getByTitle('Info'); var oListItem = oList.getItemById(listItemID); oListItem.set_item('Name','xyz');  oListItem.set_item('Address','xyz');  oListItem.update(); clientContext.executeQueryAsync(Function.createDelegate(this, this.ItemUpdate), Function.createDelegate(this, this.onQueryFailed)); function ItemUpdate(){ alert('Item updated'); } function onQueryFailed(sender,args){ alert('...

Delete Item from the SharePoint list using JSOM.

In this blog, we are going to learn, how to delete SharePoint List item using JSOM/JavaScript. We are going to delete the list item from the SharePoint list using the ID. var clientContext = new SP.ClientContext("URL of your sharepoint tenant"); var oList = clientContext.get_web().get_lists().getByTitle('Title list '); oListItem = oList.getItemById(1)); oListItem.deleteObject(); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQueryDelete), Function.createDelegate(this, this.onQueryFailed)) after successful execution of the function, it calls the onQueryDelete function and when it get failed it throws an exception. Happy Coding!!!!!