SharePoint Intranet Portal


Simulate SharePoint Online Timer Jobs Using Azure Functions

harePoint Server provides native Timer Jobs that inherit SPJobDefinition class to run at regular intervals defined in the SPSchedule object. This way, we can create solutions that have to be iteratively run to process logic at regular intervals. However, in the case of SharePoint Online, Native Timer Jobs cannot be used.

Though we can use Windows Service/Task Scheduler to simulate Timer Jobs in SharePoint Online, it is still not a complete cloud solution. However, now we have the option to create pure cloud solutions for SharePoint Online Timer Jobs using Azure Function.

What are we going to do?

In this article, we will explore the process of simulating Timer Jobs for SharePoint Online using Azure Functions. The video recording of the demo is shared here

Requirement for Simulating Timer Job in SharePoint Online using Azure web jobs

We have a List named ‘SLA’ that contains action items and an associated SLA date. Every day if the SLA date for the action item has reached, we have to intimate the concerned person about the items whose SLA has reached. Since the logic to check for SLA has to run every day, we will create a timer job solutions using Azure Function. As shown below, there are two items that have reached the SLA of 6/17/2017.


The Azure function timer job will get the SharePoint Online List items that have reached the SLA(checks if the SLA date is today) and will send the mail to the concerned Service User.


Create Azure Function to work as a SharePoint Timer

We will create an Azure Function app that will contain the code that implements the logic which will be scheduled to run at regular intervals. Once we have logged in to the Azure Portal, search for Function App and select it.


Specify the App name and the other Function App details that will be used to create the Azure Function App.


Click on Create to provision the Function App.


Once the Azure Function App is running, we can add the function where we will add the code. Select the Plus option and select ‘Timer Trigger C#’ option to simulate a timer that will run on a schedule.


We can specify a name for the Function and specify the schedule. By default it is set to run every 5 minutes.


Develop the Timer Code

Once created, it will open up the run.csx file with the below default code block.


Before adding the code to access SharePoint Online List, we must upload the SharePoint Client libraries that we will be using within the code. To do this, select the Azure Function App and from Platform Features click on Advanced Tools(Kudu).


From the Debug Console, Select the option ‘PowerShell’.


It will open the folder structure. We must navigate to the site –> wwwroot –> <Function Name> location


The function name is ‘ExpiredSLAIdenitifier’. Click on the folder to go inside the folder where we will create a new folder.


Create the New Folder and let’s name it as bin.


Finally drag and drop the client dlls which we can find at,

C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI

If we are working from a Non-SharePoint Server machine, we can download the client dlls from here .The Client Dlls that we will be using are :

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.runtime.dll


Now we can go ahead to the function and add the code that implements the logic.


By default the code fragment will look like below,


Replace the above code with the below section so that it will connect to the SharePoint Online list and fetch the list items whose SLA is today. It will also send a mail to the specified service engineer alerting the action items that has to be resolved.


  1. #r “Microsoft.SharePoint.Client.Runtime.dll” 
  2. #r “Microsoft.SharePoint.Client.dll”
  3. using System;
  4. using System.Net;
  5. using Microsoft.SharePoint.Client;
  6. public static void Run(TimerInfo myTimer, TraceWriter log)
  7. {
  8.         //In real scenario, make use of Azure Key Vault to store and retrieve password
  9.         string password = “<Your Office 365 Credential>”;
  10.         System.Security.SecureString securePassword = new System.Security.SecureString();
  11.         foreach (char pass in password) {
  12.             securePassword.AppendChar(pass);
  13.     }
  14.         //Get SPOnline User Credentials
  15.         SharePointOnlineCredentials spOnlineCredentials = newSharePointOnlineCredentials(“”, securePassword);
  16.         try{
  17.              //Create the Client Context
  18.             using (var SPClientContext = new ClientContext(   &#8220;))
  19.             {
  20.    //Instantiate List Object and get the SLA Expired items
  21.                 SPClientContext.Credentials = spOnlineCredentials;
  22.                 Web spWeb = SPClientContext.Site.RootWeb;
  23.                 List spList = spWeb.Lists.GetByTitle(“SLA”);
  24.                 CamlQuery spQuery =  new CamlQuery();
  25.                 spQuery.ViewXml = “<View><Query><Where><Eq><FieldRef Name=’SLADate’/><Value Type=’DateTime’><Today /></Value></Eq></Where></Query><RowLimit>100</RowLimit></View>”;
  26.                 ListItemCollection spListIems = spList.GetItems(spQuery);
  27.                 SPClientContext.Load(spListIems);
  28.                 SPClientContext.ExecuteQuery();
  29.                 //Email the expired items to user using SPUtility
  30.          string emailBody = “<b>Expedite the below items by EOD</b> </br><table style=’border: 1px solid black;’>”;
  31.                 foreach (ListItem spListItem in spListIems)
  32.                 {
  33.                     emailBody +=   “<tr style=’color:red;’><td><b>”+ spListItem[“Title”] +“</b></td><td>”+spListItem[“SLADate”]+“</td></tr>”;
  34.                 }
  35.                 emailBody +=  “</table>”;
  36.                 Microsoft.SharePoint.Client.Utilities.EmailProperties emailProperties = newMicrosoft.SharePoint.Client.Utilities.EmailProperties();
  37.                 emailProperties.To = new string[] { “” };
  38.                 emailProperties.Subject = “Attention : Below Items have expired their SLA”;
  39.                 emailProperties.Body = emailBody;
  40.                 Microsoft.SharePoint.Client.Utilities.Utility.SendEmail(SPClientContext, emailProperties);
  41.                 SPClientContext.ExecuteQuery();
  42.                 log.Info($“Count of List Items with Expired SLA: {spListIems.Count}”);
  43.             }
  44.         }
  45.         catch(Exception ex){
  46.             log.Info($“Azure Function Exception: {ex.Message}”);
  47.         }
  48.  }

Once the code is added, save and run the code.


The logs section will show the progress of the compilation. We have also outputted the retrieved count of the list items with expired SLA. In case we face any error, we can view these logs in the Monitor section. As shown below, I once got an authentication exception.


Demo of SharePoint Online Timer Simulation using Azure Function

The demo of the code is shown below. We have 2 items that have SLA Date as today(date the code was run is 6/17/2017)


The Azure Function has triggered and the items have been picked from SharePoint List and the mail has been triggered to Service User.


We can see the complete run time logs of the azure function by going to the Monitor section.


We can change the schedule at which the timer has to be triggered from the Integrate section as shown below. By default, it will be triggered every 5 minutes. We can set the schedule using the CRON format as mentioned here.


If we want to stop the timer from triggering we can go ahead to the Manage Section and Set the Function State to Disabled so that it doesn’t trigger unless enabled again.


Once it is disabled, we can see the function with a disabled state as shown below.


Azure Function in Action

The video recording of the demo is shared here

Rest to read more than 5000 items from document library

Here we are doing recursive call to the GetListItems() function. This will fetch data in the bunch of 1000 items and concat it to response variable.

 var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('DocumentList')/items?$select=customerID&$top=1000";
    var response = response || [];  // this variable is used for storing list items
    function GetListItems(){
        return $.ajax({
            url: url,  
            method: "GET",  
            headers: {  
                "Accept": "application/json; odata=verbose"  
            success: function(data){
                response = response.concat(data.d.results);
                if (data.d.__next) {
                    url = data.d.__next;
                $.each(response, function(index, item) {
                    arrayCustomerID[index] = item.customerID;
            error: function(error){

Reading More Than 5000 Items Using REST API In SharePoint Framework (SPFx) With Angular

Below is a simple overview of how you will get the 15000 items in a list with just 3 API calls.

First API call

ItemsToStartWith=1, TopCount=5000, Rest API Url will be formatted like below

  1. {YourSiteCollectionUrl}/_api/web/Lists/GetByTitle(‘{YourListTitle}’)/items?%24skiptoken=Paged%3DTRUE%26p_ID%3D1&%24top=5000&$select=Attachments,AttachmentFiles,*&$expand=AttachmentFiles

Second API call

ItemsToStartWith=5001, TopCount=5000, Rest API Url will be formatted like below

  1. {YourSiteCollectionUrl}/_api/web/Lists/GetByTitle(‘{YourListTitle}’)/items?%24skiptoken=Paged%3DTRUE%26p_ID%3D5001&%24top=5000&$select=Attachments,AttachmentFiles,*&$expand=AttachmentFiles

Third API call

ItemsToStartWith=10001, TopCount=5000, Rest API Url will be formatted like below

  1. {YourSiteCollectionUrl}/_api/web/Lists/GetByTitle(‘{YourListTitle}’)/items?%24skiptoken=Paged%3DTRUE%26p_ID%3D10001&%24top=5000&$select=Attachments,AttachmentFiles,*&$expand=AttachmentFiles

That’s it we have read all the 15,000 items in a list with 3 API calls.

Input mask on textbox in SharePoint list form

Input mask on textbox in SharePoint list form

Yesterday on LinkedIn I saw one discussion where one of group member asked a query about how to create Input mask on text box in SharePoint List form.

While searching on internet I found this post. In this post Author opened the new form in SharePoint designer, added custom new form and then added jQuery code on page.

But what if I do not have SharePoint designer.

So instead opening page in SharePoint designer, I added CEWP on NewForm.aspx

And then I did some changes in original code, Instead of custom style I used Title of the field. And I inserted below code in Source editor of the CEWP.

$(“input[title=’Phone’]”).mask(“(999) 999-9999? Ext.99999”);

And it worked for me. Have a look at below screenshot.

How to create count related lookup column in SharePoint custom lists?

A lookup count column is a special type of computed field that computes the number of items in the target list that point to the current item.

Let’s say I have two lists Departments and Employee Data. Now in Department list I want to add new column which will calculate how many employees are there in that department.

Here’s how we need to setup our lists:

1) Create a Department list. And add your department values in a title column.

2) Create an Employee Data list. In “Employee Data” list I renamed ‘Title’ column to ‘Employee Name’. And then add column ‘Department’ which will be lookup column pointing to the title column in the Department list.

3) After adding some test values in “Employee Data” list the list will look like this


4) Now go to “Department” list, add a column of type “Lookup” referring to the “Employee Data” list and you’ll notice that in the drop-down area where you define the lookup, you’ll have a new option called “Count Related”. This is here automatically because it recognizes that the “Department” list has a lookup pointing back to this one. Select that Count Related option.


5) Now your Department list will have a column counting how many employees are associated with that Department.


This doesn’t require any coding or JavaScript. A hidden SharePoint magic.