Skip to main content

Posts

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.