Azure

SharePoint Checklist Operation With Time Set off Azure Operate

Earlier than approaching to the Time Set off Azure let’s perceive the Azure Operate first,

Azure Operate

Azure Features is a service that permits you to launch serverless functions and run event-triggered code on Microsoft Azure with out the necessity to explicitly handle infrastructure.

Azure Features lets you write serverless code to deal with occasions at scale, with minimal overhead and value.

Time Set off Azure Operate

Timer-triggered Azure features let you run a operate on a configurable schedule. In contrast to HTTP-triggered Azure features, timing data is saved in an Azure storage account after which handed to the operate on execution.

Overview

On this article, we are going to cowl SharePoint Checklist CRUD Operation utilizing Time Set off Azure Operate. There will be many events the place we have to carry out scheduled operations with SharePoint On-line Lists. In On-Premises we used to have Timer Job to carry out any customized operations. Time Set off Azure Operate can be utilized in comparable circumstances.

Since it should schedule operation, there is not going to be any consumer interactions. We are going to Shopper ID and Shopper Secret to authenticate. We will probably be utilizing SharePoint app-only authentication.

Observe under factors,

Open the appregnew.aspx web page. click on on the Generate button to generate a shopper ID and shopper secret.

https://{tenant title}.sharepoint.com/_layouts/15/appregnew.aspx

Be aware down the retrieved info (shopper ID and shopper secret). We are going to want this within the subsequent steps.

Within the Title area, kind the title of the App. For App Area kind www.localhost.com and to Redirect URI, kind https://www.localhost.com

Create Time Set off Azure Operate Mission

For the sake of this text, we’re going to create C#.net-based Azure operate however you’ll be able to select to do it in different supported languages additionally…

Open Visual Studio (not code) – Create a brand new Mission and Select Azure Features.

  • Select Mission title and answer path and click on Subsequent it should ask you the set off kind and .NET model(as within the under screenshot).
  • Select Azure Operate and Time set off in Operate Dropdown

  • It might create the mission and you need to see one thing like under

  • First change Run Technique Argument – Change it to
    Run([TimerTrigger("0 * * * * *")]TimerInfo myTimer, ILogger log)
    TimerTrigger("0 * * * * *") – Because of this this operate will triggered in each min

    To get SharePoint Checklist knowledge, we have to set up supportive packages from NuGet Supervisor. Go to Instruments-> NuGet Package deal Supervisor – Handle NuGet Packages for Options

  • Browse “Microsoft.SharePoint.Shopper.newest” and set up it.

  • Browse “PnP.Framework” and set up it.

As soon as it’s put in it is going to be seen underneath Put in tab.

  • We’re all set to jot down our code to get SharePoint Checklist knowledge.
  • Initialize Website URL (Your website URL), Shopper ID and Shopper Secret Worth (Values now we have famous earlier).

Use under code,

utilizing System;
utilizing Microsoft.Azure.WebJobs;
utilizing Microsoft.Azure.WebJobs.Host;
utilizing Microsoft.Extensions.Logging;
utilizing Microsoft.SharePoint.Shopper;
utilizing System.Linq;
utilizing PnP.Framework;
namespace AFGetListItem {
    public class Function1 {
        [FunctionName("Function1")]
        public void Run([TimerTrigger("0 * * * * *")] TimerInfo myTimer, ILogger log) {
            log.LogInformation($ "C# Timer set off operate executed at: {DateTime.Now}");
            strive {
                string siteUrl = "Your Website Url";
                string ClientSecret = "YourClientID";
                string ClientId = "ClientSecret";
                utilizing(var clientContext = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, ClientId, ClientSecret)) {
                    Internet oWebsite = clientContext.Internet;
                    Checklist checklist = oWebsite.Lists.GetByTitle("CustomList");
                    clientContext.Load(checklist);
                    clientContext.ExecuteQuery();
                    CamlQuery question = CamlQuery.CreateAllItemsQuery();
                    ListItemCollection gadgets = checklist.GetItems(question);
                    clientContext.Load(gadgets);
                    clientContext.ExecuteQuery();
                    string consequence = " CustomList gadgets Depend: " + gadgets.Depend();
                    log.LogInformation(consequence);
                    foreach(ListItem itm in gadgets) {
                        Console.WriteLine("Title: " + itm["Title"]);
                    }
                }
            } catch (Exception ex) {
                log.LogInformation($ "C# Timer set off operate executed Exception at:" + ex.Message);
            }
        }
    }
}

Take a look at the Mission

Run the Mission utilizing F5 and be sure you are seeing under the window

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button