How can we help you today?

How to Display the Number of Likes from the SharePoint List Items

If you would like to display the number of likes from your SharePoint list items, this article is for you. It is possible to achieve that using ShortPoint REST API connection type.


Note: For the purposes of this article, we are going to use Simple List Design Element. However, you may use any Design Element to your liking.


Here is how it may look like on your page:


Result example


And a closer look at the likes in Simple List:


Likes in a Simple List


NoteShortPoint Page Builder Live Mode was formerly known as Visual Builder and Grid Mode was formerly known as Wireframe Builder.


TABLE OF CONTENTS


Before we begin

  • The "Like" feature should be enabled on the SharePoint List / Library. Please note that this feature is only available for Modern Teams sites. If you are using Modern Communication Sites, this solution will not be possible.
  • To enable the Like feature, open your SharePoint List / Library settings. Then, select the Rating settings:

Settings 

From there, set the Rating Settings to "Yes" and choose the "Likes" option. Then, click OK. It will display “Like” button in the List / Library.


Enable Likes feature

  • Make sure that the Likes column is displayed in your List / Library view.

Number of Likes


If it is not displayed, click Add column > Show/hide columns, select Number of Likes column and click Apply.


Add columnEdit view columns

Step 1: Edit Simple List Design Element


In edit mode of the page, open the settings of your Simple List Design Element.


Info: 

Currently, configuring ShortPoint connections is only supported in the Grid Mode. Make sure to switch to it, if you are in the Live Mode:


Switch to the Wireframe Builder


Click the cog wheel icon as shown below: 


  • New ShortPoint Page Builder Grid Mode:

Edit Simple List - New Wireframe Builder


  • Legacy Page Builder:

Edit Simple List - Legacy Wireframe Builder

The Items tab will open.


Step 2: Configure the REST API settings


2.1 Set up the REST API connection URL


Switch to the Connect tab and choose REST API from the connection options:


Connect tab - REST API


In the REST API URL, paste the following URL (items highlighted with red and yellow require editing):

https://siteURL/_api/web/lists/getByTitle('listTitle')/items


  • siteURL- should be replaced with the site URL (root site, site collection, subsite) where the SharePoint list is located;
  • listTitle  - should be replaced with the title of the SharePoint list, you would like to connect to.


For example, our REST API URL looks like this:

https://mycompany.sharepoint.com/_api/web/lists/getbytitle('Company Announcements')/items


Where:

  • mycompany.sharepoint.com is the site collection URL where our SharePoint list is located;
  • Company Announcements  is the title of our SharePoint list.


Important: In order to filter/sort/expand results, you need to add the appropriate parameters to the URL. Make sure you add the LikesCount field in the $select clause. Check more information about it in the following article: Using REST API For Selecting, Filtering, Sorting And Pagination in SharePoint List.



In our case, to select the likes count, the REST API URL will look like this:

https://mycompany.sharepoint.com/_api/web/lists/getbytitle('Company Announcements')/items?&select=LikesCount


REST API URL example


Click Connect


Click Connect


2.2 Prepare the Mapping Function


If you inspect the Data Example field value, you would be able to see the LikesCount field between the other properties returned by the API:


LikesCount in Data Example


As you may see, for those items that don't have any likes, the value of the LikesCount value will be null. In order to display 0, you should update the Map Results function.


Please copy the following code:

var results = data.d.results;
for (var i = 0; i < results.length; i++) {
    if(!results[i].LikesCount)
    results[i].LikesCount= 0;
}

return results;

2.3 Update the Advanced Settings


In the same Connect tab, disconnect and then Enable Advanced Settings:


Enable Advanced Settings


Scroll down to the Map Results section and paste the code from the step 2.2:


Map Results


2.4 Connect to the REST API


Click the Connect button:


Connect button


After you see that the connection is successful, proceed to the next step to map the items:


Connected successfully


Step 3: Map the Items


Switch to the Items tab:


Items tab


Press the chain icon on the right of the Design Element field (for example, Title) and select which column of your SharePoint list/library correspond to it:


Chain icon - items mapping


Note: To know more about items mapping, please check our ShortPoint Connect: Basic Tutorial.


In our case, we are mapping Title to Title, Subtitle to the LikesCount, and Description to the Description.


You may click the Preview button to check the results:


Preview button


Hint: The heart icon that you can see in the screenshot is just a text character that you could copy and paste from the web (for example, from the AltCodeUnicode website).


Then click Update to save your changes:

Click Update


Result


Here is how it may look like on your page:


Result example Happy REST-connecting!


Related articles:

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.

World's best intranet sites are designed using ShortPoint

Get started today! Learn more
See all 31 topics

Start a trial

Ignite your vision. Install ShortPoint directly on your site, or play in sandbox mode. No credit card required.

Get started today

World’s best intranet sites are designed using ShortPoint

Thousands of companies using ShortPoint everyday to design, brand and build award winning intranet sites.

Get started Learn more