attach scheduled report to task

russellprice
Tera Contributor

Hi

We currently have a scheduled task which is triggered every week to check cert expiries. We also have a scheduled report which emails the current certs which are due to expire.

I was wondering wether there was a way to get the scheduled report to automaticaly attach itself to the scheduled task so that there is no need to search for the email in your inbox?

Thanks

Russell

1 ACCEPTED SOLUTION

Again getting a report attached to a task is tricky so hopefully this solution will satisfy your requirements.  Idea is that your list of expired certs will show up as Affected CI's on this custom task.  From there you can drill into them to see details on the certificate and its "Affected by Task" list.  In my testing of this solution, I created an incident, but it doesn't matter which type of task you are creating.

 

The description field gets set by a list of certificate names:

find_real_file.png

 

The Affected CI list is populated with this same list of certificates:

find_real_file.png

 

  • Navigate to your existing scheduled job and deactivate it.
  • Navigate to System Definition\Scheduled Jobs and click New
  • Choose "Automatically run a script of your choosing"
  • Give it a name that makes sense to you
  • Set the schedule to run it
  • Paste in the following code.  I put in comments so you know whats happening to make tweaks
// Enter the SysID of the template used to create the task
var templateID = "90bc17044f751b00d1676bd18110c716";

var templateRec = new GlideRecord("sys_template");
if (templateRec.get(templateID)) {
	var taskTableName = templateRec.table;
	
	// Initialize task record and apply template
	var taskRec = new GlideRecord(taskTableName);
	taskRec.newRecord();
	GlideTemplate.get(templateID).apply(taskRec);
	
	// Get a list of expired certificates and add as Affected CI
	var certNameList = [];
	var certRec = new GlideRecord("u_cmdb_ci_certificates");
	certRec.addEncodedQuery("u_expiration_days<30^install_status=102^EQ");
	certRec.query();
	while (certRec.next()) {
		certNameList.push(certRec.getDisplayValue());
		var affectedCI = new GlideRecord("task_ci");
		affectedCI.ci_item = certRec.sys_id;
		affectedCI.task = taskRec.sys_id;
		affectedCI.insert();
	}
	
	// Set list of certificates into task description field
	var certDescription = "List of expired certificates:\n";
	certDescription = certDescription + certNameList.join(", ");
	if (gs.nil(taskRec.description)) {
		taskRec.description = certDescription;
	} else {
		taskRec.description = taskRec.description + "\n" + certDescription;
	}
	
	// Insert Task
	taskRec.insert();
	
} else {
	gs.log("Cannot create expired certificate task because no template found");
}

Please let me know if you have any questions.

View solution in original post

16 REPLIES 16

What is generating the scheduled weekly task?  That is what I am suggesting you edit to include the report detail so instead of needing a report, the task just includes the information as a comment of the task or related CI's attached to that task.

Honestly you should consider using the Support Group or Owned by attributes on the cmdb and set that on each of the cert CI's to its owner.  Then have a scheduled job send an email to the owners X days from expiration reminding them that their cert is about to expire which will reduce time by your analyst all together.

the job type is "scheduled Entity generation" if that means anything to you?

I 100% agree to sending the support group an automatic email but these are being ignored and certs are expiring so the powers that be want our department to take a 'pro active' role and actively chase if they get close to expiring.

 

Im just trying to find the most pain free way of doing it.

OK so you are using "automatically generate" a task via a template functionality.  As mentioned I believe the best solution would be to have your task to have a list of the "impacted" certs attached to it via related list using the Affected CI list.  Would this work?

 

Several questions:

  • How are you with scripting?  I can coach you along but there are specific things in your instance that will need to be added to the script.
  • What type of task is generated today?  Incident, custom task, ?
  • What is the CI table name your certs are stored in?
  • What query are you using to find the expired certs?

 

So my proposed solution would be to remove your existing "scheduled entity generation" scheduled job and instead run a script on a scheduled basis that will generate the task via the same template, but would also attach the expired certs to this task via Affected CI list.

Hi Michael

I understand scripting enough to be able to customise a script to work in my instance, anything more that that will be a challenge, but I'm always up for a challenge! 😄

It just generates a custom task

The table name the certificates are in is - u_cmdb_ci_certificates

The filter for the report is u_expiration_days<30^install_status=102^EQ. This Shows all the certificates in u_cmdb_ci_certificates which expire in less than 30 days. There are also tasks related to these certificates under "Affected by Task" I would like to add to the report. is there any way I can do this?

Really appreciate you help in this

Thanks

Russell

What type of field is "u_expiration_days" on the certificate table?  The query looks a little strange for a date type field.

 

Regarding the ability to view Affected by Task on the same list, that will be difficult because of the many to many nature of this.  For example you may have 3 certificates expiring this week and showing all the tasks of those 3 certificates may be confusing.  Its possible with a "defined related list" that could show all of this.