Skip to main content

Create Timer Job In SharePoint-2010


Create Timer Job In SharePoint-2010 

A Timer Job is used to execute the tasks which needs to be execute periodically  inside SharePoint Server. It can perform various tasks 
within the SharePoint Farm on a scheduled time.

Components of Timer Job

Derive CustomTimerJob Class from SPJobDefinition.

•there are three Constructors of the derived class which will execute when ever the object of CustomTimerJob class is created.

Override the Execute method:  Execute method will run when ever the timer job start running. this method contains the logic. 

• To add Timer Job in SharePoint farm or to remove time job from SharePoint, we can use the feature and feature receiver. So, we need to create a Feature and Feature Receiver.

Timer Class(Timer Job Definition) 

Part-1  Derived from SPJobDifinition

using Microsoft.SharePoint;  

using Microsoft.SharePoint.Administration;  

public class TimerJobDemo:SPJobDefinition  
{                                                 }

Part-2 There are three Constructor

public TimerJobDemo():base()  
{                                                                                             }  
public TimerJobDemo (string TimerjobNameSPService service) : base(jobName, service, nullSPJobLockType.None)  

{      this.Title = "Demo Timer Job";  }    

public TimerJobDemo(string TimerjobNameSPWebApplication webapp) : base(jobNamewebappnullSPJobLockType.ContentDatabase)  

{       this.Title = "Demo Timer Job";   }  

Yellow color constructor represents a default constructor.

Light blue color constructor represents web service association constructor .

Green color constructor  represents the  service application association constructor .

Part-3 Execute Method-

Override the Execute() method to do your stuff.

public override void Execute(Guid targetInstanceId)

If Lock type is 'ContentDatabase',  the 'targetInstanceId' parameter means the GUID of the content database that need to replace the 'targetInstanceId' parameter. Otherwise no need to mention this parameter. this method contains the whole logic that will performed by timer job to complete the business requirement.

Discussion-

•  Need to create default (parameter-less) constructor for deserialization purposes. 

The 'SPJobDefinition' class is a inherit class from the SPPersistedObject class.

If a default parameter-less constructor is not implement in time job, error message as mentioned below will received during debugging when we call .Update() in timer job.

Error Message- TimerJobClassName cannot be deserialized because not having a public default constructor.

There are four values that we need to mention in constructor that are  given below.

Web Application or Web Service Association Reference

Server Association Reference (optional)

Name of the timer job

Lock Type of the Job

LockType

 We have to define SPJobLockType value in the timer job instance constructor that value helps to identified where and how many times the timer job will run. There are three type of Locks values which are mentioned below. 

    None- means there are no locks applied on this timer job. It will run only one time on each SharePoint servers in farm.  but if the parent web application or service application with which the timer job is associated has been provisioned to that server. 

   Content DatabaseIndicates that the timer job will run once for each content database associated with the web application with which the timer job is associated. If one content database is associated with web application, it will run once. If multiple content databases like 10 are associated, then it will run ten times. When you specify this option, the targetInstanceId parameter on the Execute method will be populated with the GUID of the content database for which the timer job is firing. 

     Job-  Indicates that the job will run only one time.

Scope of timer job
Farm- Activated feature for entire server farm.

Site-  if scope is Site, timer job feature need to be activated at  site collection. Timer job will work for the all subsite under the this site collection.

Web-  Timer Job feature need to be activated at the subsite level.

WebApplication- Activated a feature for all web sites in a web application.

Generally  we set web application scope to feature.

Note-  In SP 2013, Timer Job has four different type of scope as mentioned above but in SP 2010, timer job has two scope that are Site collection and Web Application.

Feature Properties- there are two important properties which is need

   “Active On Default” must be set to “False
   “ Always Force Install” generally set to “True”
                  
                                       

Comments

Popular posts from this blog

Difference between SharePoint Online PowerShell and PnP PowerShell

  Difference between SharePoint Online PowerShell (SPO) and PnP PowerShell (SPO vs PnP) Basically,  during interview these topics like Difference between SPO and PnP, Connect with SharePoint by PowerShell Command are very common to be discussed. We will start from the Difference between SPO and PnP. At the end, we will also discuss 'How can connect to SharePoint online by using the SPO and PnP commands?' Question-1 Difference between SPO and PnP?   PnP PowerShell-   It is managed by Patterns and Practices team.   It can be used for SharePoint Server as well as SharePoint Online. it means that is a  cross platform library.   It works in context of the current user. It mean that no need to have tenant level /SharePoint administrator right to manage.     It works at level of site collection.   It has wide range of commands at Site, List and Item level. SharePoint Online (SPO) PowerShell-   It is managed by Microsoft ...

Disable User filtering in SharePoint 2010

Remove Disabled User from People Picker As we know experience always better then theory but good combination is experience plus theory of relative experience. This combination enhances your knowledge. Today, we have a critical reporting issue from client that is “ Employee has left organization but Employee is still in People Picker” . This issue is related to User profile Synchronization. To overcome this issue we need to creating User profile Synchronization Exclusion Filters using the Active Directory Attribute ”userAccountControl”. Exclusion filter has an advantage of reducing the amount of “Junk” in the profile database and also decrease the time taken to perform synchronization. The userAccountControl attribute is used to store the account options for an AD user object. These options include the status of the account (e.g. disabled, or locked out). Each option is a property flag. These flags are cumulative and thus there is only ever one value for userAccou...

Calendar Overlay Issue

Error - ' Unable to find  specified web in the given URL' Above given Error Message is related to SharePoint Calendar. To resolve this problem, SharePoint Calendar Overlay functionality need to be understand. SharePoint  Calendar Overlay works well for site collections in the same web application, but not for across web application. Steps for Resolve this Error- 1- Verify the Calendar Overlay Setting and clicking on Calendar Overlay button in calendar ribbon. 2- Check your URL in web URl field. This is same as defined in AAM. click on resolve. 3- Check List and List view.  Verify that your url is resolved,  Automatically all fields will be filled. List view field value will be your calendar name. 4- Click on save. Now check your calendar and your problem will be resolved. Note-  Please check out your page on which calendar is rendered before doing Troubleshooting. Thanks........

Default Web Services in SharePoint

By default, SharePoint has multiple web services that are given below. http://ServerName:99999/_vti_adm/Admin.asmx – used for creating and deleting sites, change 99999 with your administrative port number http://ServerName/_vti_bin/Alerts.asmx – used for working with alerts http://ServerName/_vti_bin/DspSts.asmx – used for retrieving schemas and data http://ServerName/_vti_bin/DWS.asmx – used for working with Document Workspaces http://ServerName/_vti_bin/Forms.asmx – used for working with user interface forms http://ServerName/_vti_bin/Imaging.asmx – used for working with picture libraries http://ServerName/_vti_bin/Lists.asmx – used for working with lists http://ServerName/_vti_bin/Meetings.asmx – used for working with Meeting Workspaces http://ServerName/_vti_bin/Permissions.asmx – used for working with SharePoint Services security http://ServerName/_vti_bin/SiteData.asmx – used by Windows SharePoint Portal ServerName http://ServerName/_vti_bin/Sites.asmx – used to ret...

Six Pillars of SharePoint-2010

Six Pillars of SharePoint SharePoint Server/ SharePoint Online has six pillars basically Six core areas that make it popular in IT industry . SharePoint Online is a cloud version of SharePoint server. it is integrated application in Microsoft 365/Office 365. 1- Sites SharePoint Sever has core functionality to  allows users to create different type of site like team, project, enterprise search center etc. in just a few clicks or hardly with in 5 to 10 mins. Newly created site will be in ready to use mode without any coding.    2- Communities SharePoint Server provides great teamwork tools like team site, news, blogs etc. that allow users to share  information, find out the information, and discuss with people with in organization boundaries. 3- Content SharePoint Provides the functionality to user to create and manage content easier as compare to other content management systems available in market. it is also integrated with  Microsoft office. ...

Fetch Data From Multiple SharePoint Lists

                                                Fetch Data From Multiple SharePoint Lists Today, we have a very interesting Topic  that is "Fetch Data From Multiple SharePoint Lists" to discussion.  there are many ideas by which it can be happened. here we have three methods which are following- 1- By using CQWP- this is totally depends on search service application. it can be implemented by SharePoint administrator by using User interface.  you only needed a query to fetch data from search. here search service application is playing a important role so it also has an impact on your CQWP which is added in web part zone on .aspx page. 2- By using Linked Data Source- This can be done by using SharePoint Designer. Linked data source is configured for multiple SharePoint lists through SharePoint designer. after Configuration of linked data source, Jus...

Create file with dynamic name by using PowerShell

Power Shell is a scripting language which has amazing capabilities to automate the administrative tasks without any intervenes. By using it, log files can be created and deleted after some duration like after 7 days, 30 days etc.   This is a common task that is performed by window administrators. Let me take an example like Application logs files are created in production environment. Day by Day Size of the log folder is increased due to log files those are created on daily bases. In directly, log folder is utilizing the server space. This will affect the server performance. To clean the log folder dynamically on daily bases, Power shell script can help. Below we will write the script to perform same task by understanding with below mention topics. How can create a log file with dynamic name by using PowerShell? How can delete log files after 7 days by using Power Shell? How can create a log file with dynamic name by using PowerShell? Main problem is log files name must be un...

Target Audience in SharePoint Online (News Web part & Event Web Part)

Target Audience in SharePoint Online (News Web Part & Event Web Part) SharePoint has target audience feature to hide and show the information for the authorized audience. That is  the way to manage the critical information only for required group of people that is called Audience. In SharePoint Online, few out of box web parts which are following below supports audience targeting. News Web part Events Web part Highlighted Content Web part Quick links Web part At Site Page library Navigation links Viva Connection Dashboard In this blog, Only News Web Part  and Event Web Part will be discussed. New Web part –  Whenever any author is creating news post. It creates in Site Page library as a new page.  So enable audience targeting is a two-step process that are given below. Enable audience targeting at Page Library in which your news pages are created. Enable audience targeting at the news web part level. We will discuss one by one each pro...

Targeting Audience with SharePoint

   Target Audience with SharePoint   Targeting audience in SharePoint Server is key functionality to manage the information access to specific set of employees on SharePoint site pages. In interview common question is"  how can handled a set of people with same interest I mean group of people which are from Same departments like Sale, HR, Management etc. in an Organization ". Lets Start answering for this question. Basically SharePoint has multiple ways to handle Target Audience for different type of content. which are following- 1- Set Target Audience for a Web Part-  This is very common way to handle Target Incidence. this used by SharePoint Administrator. Target audience is supported by few Out of Box Web Parts like Content editor. To set the audience, First move page in edit mode then edit the Content editor Web Part. set the audience name in audience field. 2- Display  SharePoint List  and Library items  in Webpart  to Targ...

Custom Master Page In SharePoint-2013

Custom Master Page In SharePoint-2013 Today We are Going to  creating  a custom Master Page for SharePoint 2013 using Visual Studio 2012. The Process is similar as was done in SharePoint 2010. Steps  are following  to create my custom Master Page: Step-1 Take a copy of your SharePoint-2013 master pages like Seattle.master and Oslo.master from  the               directory "15\TEMPLATE\GLOBAL". Paste this master page in a folder and rename the file like                     (i.e Custommaster.master) Step-2 Add a new Module(name like CustomMasterPage) and delete sample.txt file that was created                    automatically by adding module. Step-3 Add Custommaster.master file to the Module and change some Parameters like                           ...