Skip to main content

Posts

Notable changes in List in SharePoint Online

The moment you create a List in SharePoint Online there are quite a few notable changes which catches our attention. Let me provide a quick list of those changes. AllItems View In AllItems View, we don't see ribbons any more. Instead there is a menu which has all the required actions for a List. Columns can be added right from the view itself. This is really useful considering it minimizes steps to create columns. We can also change the order of column display in the view by simply dragging a column. What I also noticed is the List view has ajax implemented. If someone adds an item to the list, it automatically refreshes in my screen. I liked this feature. List Settings List Settings option is available under "gear icon". It took a while to figure this out. So the options available in gear icon is contextual. If I'm not in a List view, this icon will not show me "List Settings". Versioning Settings Now If you enable versioning, it is mandatory to set the num...

Update on SharePoint Posts

Now it's more than a decade in SharePoint technology. I had a privilege to work in many areas within and around SharePoint and in various domains solving business problems. Though, I'm still working on SharePoint, I have also developed an interest in Machine Learning. From the blogging perspective, my current focus is on ML concepts and programming. I find the ML programming different from traditional programming which I have been doing. There is a learning curve and I'm enjoying it. I have created a separate blog space to share my ML journey . I do not have plans to stop writing on SharePoint, but definitely the frequency may reduce substantially  I would continue to write on SharePoint Online and related technologies. 

Get User Id using REST or JavaScript Object Model

Sometimes you would need to fetch the User Id based on either Login name or Email id. You would need User Id if you need to assign a user object to a people picker control or People/Group field. How do we get the Id based on Email or Login Name in client side development? We can achieve that using JavaScript Object Model or REST API. Let me share the first example using JavaScript Object Model (JSOM). var context = new SP.ClientContext.get_current(); this.user = context.get_web().ensureUser(loginName or Email); var o = { d: d, user: this.user }; context.load(this.user); context.executeQueryAsync(     Function.createDelegate(o, ensureUserSuccess),     Function.createDelegate(o, Fail) ); The above code fetches User Id for a given Login Name or Email Id. Interestingly, there is no equivalent endpoint available in REST! The Microsoft documentation talk about a endpoint but I could not get it working. So what is the way to get User Id using REST? You h...

Maintaining Multi-line text format in Angular

In my earlier post, I had discussed about maintaining multi-line text format in AngularJS view . In this post, I'll share how to achieve the same in Angular. What I have described in this post is tested in Angular 7. To provide a context, let us say you are creating a page using Angular and rendering data from a SharePoint list/library. One of the columns is multiple lines of text with rich text enabled. The objective is to display the rich text as it is. In AngularJS, we created a custom filter and used that filter in the HTML element. In Angular, it is pretty easy. Angular already provides [innerHTML] property to handle such cases. Let's look at an example. <p [innerHTML]="description"></p> Here, "description" is a property in Angular component which holds the value of a multi-line text column. If you are thinking if it is safe to use this, check the Angular documentation on security  (yes, it is safe!)

Update on Posts and Comments

I have seen many comments in last several months asking questions on some of the posts. First of all, I apologies for not responding on time. I had set email to receive notification for new comments but for some weird reasons, I was not getting mails at all. Since I did not check for new comments in the site itself, I did not even know that there were comments, so I could not respond to your questions. I'm trying to fix this notification issue. Meanwhile, I'll keep checking in the site itself for any new comments. Also I have observed, there were plenty of spam comments in the site. I had kept posting comments open but looks like spammers have taken the advantage of it for their product/service marketing. It took quite a bit of time to individually delete all the spam comments. Going forward, all the comments will be moderated. That means, it will not be published immediately. I hate to do this but this is the only way to filter spam comments. I'll also make sure to ch...

UnauthorizedAccessException while checking If user is part of a Group

To check if a user is part of a group programmatically, we can use this end point: $.ajax({     type: "GET",     url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getbyname('groupName')/users?$filter=Id eq " + userId,     headers: {"accept": "application/json; odata=verbose"},     success: function(data){      // Success logic     },     error: function(error){       alert("Error");       console.log(error);     }   });  When you execute this code, and (if) you get the below error Access denied. You do not have permission to perform this action or access this resource 401 System.UnauthorizedAccessException Navigate to the group, go to Group settings, and ensure "Who can view the membership of the group?" to "Everyone". By default, only the Group Owner can view the membership ...

Announcement of SharePoint 2019

The last month, Microsoft announced the strategy, vision, and timeline for SharePoint 2019. From the screenshots provided, it is evident User Experience has improved. Though the article has listed the key features, we have to wait to experience what changes SharePoint 2019 brings to the users. SharePoint 2019 is available to the customers in second half of this year. Preview should be available to the customers soon. Check this article for details.

Filter on Date column of a Calendar List using REST API

In SharePoint 2013 on-premises site, if you are trying to apply a filter on EndDate column (or EventDate column) of a Calendar List using REST API, it throws the below error. The field 'EndDate' of type 'DateTime' cannot be used in the query filter expression. Basically we cannot use EndDate column in the filter query. That sounds weird but it looks to be a "miss" from the SharePoint product team. However, it is interesting to note that this filter works fine in SharePoint Online (SPO). So the sample query like below returned valid items. https://domain/sites/pub/_api/web/lists/getByTitle('Calendar')/items?$select=Title,EndDate&$filter=EndDate lt '2018-05-31T23:59:00Z' So, the Product team might have fixed the issue in SPO. Hope this should be resolved at least in SP2016.

Send items to Recycle Bin using REST

When we have to implement Delete operation using REST API, we normally use the straightforward method to delete an item or a document. For example, to delete an item from a List, we use the following code. $.ajax({   type: "POST",   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('CustomList')/items(2)",   headers: {     "accept": "application/json; odata=verbose",      "X-HTTP-METHOD": "DELETE",      "IF-MATCH": "*",      "X-RequestDigest": $("#__REQUESTDIGEST").val()  },  success: function(data){      alert("Item is deleted!");  },  error: function(error){      alert("Error"); console.log(error);  } }); To delete a document from a Library, we use the below code. $.ajax({   type: "POST",   url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfilebyserverre...

How to check User permission using REST

Though SharePoint handles security trimming throughout the site, sometimes when you need to create custom pages and controls, you would need to check the permissions of the logged in user to allow/block certain actions. For example, only if a user has permission  to edit list items, show Edit button. So how do you check if the logged-in user has the required permission or not? SharePoint provides a REST endpoint "effectiveBasePermissions". Using this endpoint, you can check if the user has required permission or not. THE URL syntax is: [Domain]/[Site]/_api/web/lists/getByTitle('ListName')/effectiveBasePermissions . Interestingly, this endpoint returns data as JavaScript Object Model (JSOM) object. So to use this data, you would need to load two libraries sp.runtime.debug.js and sp.debug.js. These libraries are available at 15 hive folder. Let me show you the complete code (jQuery should be loaded for this code). This code is tested in SharePoint Online and it...

SharePoint Custom Page - Page not found error

I came across an interesting behavior. I had created a custom page with custom logic. I had to pass a parameter and a number so that I can use the value in the code. So the URL looks something like this: http://[Domain]/[SiteCollection]/Page/MyCustomPage.aspx?Id=[number] When I navigate to this page, MyCustomPage was not loading, instead SharePoint was giving "Page not found" error. If I navigate to the same page without passing a parameter, it renders the page without any problem. That means, when I pass a parameter in the URL, SharePoint was treating the entire URL as a page URL. Since it doesn't exist, it was throwing page not found error. This was one of those weird behaviors which is hard to comprehend. After a bit of Googling, I came across this article by Stefan Goßner . In this article Stefan lists some of the parameters which we should not be using as they are reserved query string parameters. Though the article is specific to MOSS 2007 and SharePoint 20...

Security Trimming and REST

Security trimming is an important feature in SharePoint. The permissions defined in a site is "respected" throughout the site including the APIs. So once you define a permission, wherever you navigate, the permissions are applied and accordingly you will (not) see the data. What does it also mean that if you are using REST API to fetch data from a SharePoint site, the API returns data with security trimmed. So you don't have to apply any additional filter to the query. The same query might return 10 items for one user, 20 items for another user based on the user's permission on items. Also, let us say, you are trying to get a list of Apps (Libraries and Lists) from a site using REST and you are displaying that on a page. Also assume that you have not given permission to 5 out of 10 Apps to the user "User A". How many Apps User A get to see in a page? It's not 5 but all. Remember, this is similar to the case where user navigate to Site Contents pag...

How to fetch value from Rich Text editor using jquery

When we use multi-line text in SharePoint List, Rich Text Editor will be rendered on List forms. If you ever need to apply a custom validation on this control, you would need to fetch values programmatically. So how can we fetch value from a rich text editor. As a first step, open the List form using SharePoint Designer. Replace the control ID (eg., ff1) with a custom name. Let us say Desc. Every rich text editor is basically a "contenteditable" DIV. We cannot use ID completely. So we need to use wildcard and also use role attribute which is always "textbox" for rich text editor. So your jQuery code looks like this: $("[role=textbox][id*='Desc']").html(); By using role attribute and the field name, you are assured of getting the value of a multi-line text field.

REST API error: The query to field is not valid

I stumbled upon this error when I was trying to fetch items from SharePoint List using REST API. The query to field 'ExpandColumn/ColumnName' is not valid After a quick research, I found that we get this error if we are trying to fetch multi-line text column through $expand query. What does it mean? If you have a lookup column, and if you want to fetch columns through a lookup column, you can use $expand query. Though it works for fields such as Single line of text, Date, Numeric etc, this $expand query will not fetch multi-line text columns. The workaround for this limitation is you would need to make two REST calls - one to fetch the List items, and the other to fetch corresponding multi-line text value from the lookup list directly.

REST equivalent of AddToCurrentScopeOnly method

When we have to programmatically apply fine grain permissions to the List items, we have to ensure the ACL (Access Control List) limit is under control as defined in Software Boundaries. Typically, in Server side object model (SSOM), Microsoft provides a method called AddToCurrentScopeOnly . The best practice document also suggest to use this method. To quote what is mentioned in the above article: Use the AddToCurrentScopeOnly method to assign Limited Access membership in a SharePoint group. The key element in this principle is to redesign the architecture so that scope membership does not cause Access Control List (ACL) recalculation at the parent document library and web. In fact, I have used this method in SSOM and it works fine. So when I had to apply fine grain permission to the List items using REST API, I was looking for an endpoint for AddToCurrentScopeOnly. But I could not find any reference in MSDN. It turned out that this method is not available in client side APIs in...

How to clear multi-value Lookup field using REST API

Last year, I had written a post on updating a multi-value Lookup field using REST API . When you are updating a multi-value lookup column, sometimes you would also need to clear the column. The way we can clear a multi-value lookup column is different than how we would do for a single value lookup column using REST API. For a single value lookup column, setting a null clears the value. However, for multi-value lookup column, setting a null or blank space does not work. Why? Remember, when you are updating a multi-value column, you would set an array object with the key "results". So to clear a multi-value lookup column, we need to assign the key "results" to an empty array as shown below: { "ColumnId": { "results": [] } } So if you are using REST API to update a multi-value column, do ensure to have this use case as well to clear the column.

The year gone by

The year 2017 was very hectic - both in professional and personal lives. I could not contribute much in this SharePoint blog, even though there were a lot of learning. However, I have made it a point to contribute more in 2018. I just need to do a better planning and execution. Well, at the end of this year, I'll check how far I've been able to contribute to the SharePoint community. Wish you all a very happy and successful New Year 2018!!!

How to get SharePoint List or Library GUID via REST

Sometimes, you would need List or Library GUID to use that in some operation. In such cases, how do you get hold of GUID using REST API? There is a straight-forward end point which you can use: /_api/web/lists/getByTitle('ListTitle')/Id This will return the GUID of a List or Library. There is also another approach. However this approach works only if a List or Library contains at least one item. /_api/web/lists/getByTitle('ListTitle')/items This is a familiar end point which we use to fetch items of a List or Library. To get the GUID from the response, you would do: var listIDTemp = response.data.d.results[0].__metadata.id; var listID = listIDTemp.substring(listIDTemp.lastIndexOf("guid") + 5).split('\'')[0]; As you can see, we are doing string operations to fetch GUID from metadata.id. This contains information only if the response has at least one item.

Difference between Choice and Lookup fields in SharePoint

When you have to provide users an option of selecting a value from a list, you can go for a Choice field or a Lookup field. Have you ever wondered which one to use and when? Which option should be chosen over other? To address these questions, one need to understand the differences between these two data types in SharePoint. This post outlines these differences to help users decide the appropriate column type based on their needs. Factor Choice Lookup Permission To add values to a Choice field, you need minimum Design permission To add values to a Lookup field, you need minimum Contribute/Add permission Changing existing Values If you change a value in a Choice field, it does not affect the existing values. For example, let us say one of the values was NY and there are items with this value. If you change it to New York in the field schema, it only affects the new values. All existing values will retain NY. If you change a value in a Lookup field, all the existing rows re...