SharePoint Experts, Information Architects, Expert Witness

SICG provides a broad array of business and technology consulting from architecture to design to deployment of global systems with a focus on surfacing data in the enterprise. We focus on the "How", not just the possible. Contact me direct: david_sterling@sterling-consulting.com or call 704-873-8846 x704.

Search This Blog

Sunday, August 6, 2017

Adding a Description to your Timer Jobs (SharePoint 2013/2016)

I know, been a while since I needed one but had to build a few timer jobs for an On Premise location. As in the past, there's a 'bug' in the Timer Job namespace where in you cannot add a 'description' (it's read only due to crappy development).

I had to do some research having not touched these for quite a while so posting here so I don't have to remember (again).

To add a description, you have to override the "Description" in the timer job and provide your own, then you have to add it to all three of the class definitions. In this case it was a timer job to purge documents after 72 hours.

The Override and new description property:

        /// <summary>
        /// Description - Override built-in Description property
        /// </summary>
        public override string Description
        {
            get
            { return CustomDescription; }
        }
        /// <summary>
        /// CustomDescription - Used to provide "Set" to the Job Description
        /// </summary>
        private string CustomDescription
        {
            get;
            set;
        }

Adding to the the class def

             public PurgeAfter72HoursClass() : base()
        {
            this.Title = JobName;
            this.CustomDescription = JobDescription;
        }

        public PurgeAfter72HoursClass(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType)
        {
            this.Title = JobName;
            this.CustomDescription = JobDescription;
        }

        public PurgeAfter72HoursClass(string jobName, SPWebApplication webApplication, string strUrl)
            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {
            this.Title = JobName;
            this.CustomDescription = JobDescription;
        }

Have fun!


No comments: