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

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

If it were me, I would suggest the following:

  • Remove the scheduled report as its redundant
  • Create a scheduled job that will query for expired certs and create a task with the details.  If no expired certs, no task.
    • Assuming expired certs are CI's you can populate the Affected CI list with the list of expired certs
    • You could also post a list in a comments type field as well
  • Create a notification for this task to send an email to whomever once a task is created.  This way if no expired certs, no email.

Awesome! thanks for the speedy reply!

However, I have just been told that neither a scheduled report nor publishing the report will be sufficient as the analyst will need to be able to click on the certificate CI and support group to be able to view current work notes etc.

Im thinking that the easiest way to deal with this is just put a copy of the report URL in the task itself, although it seems a bit of a dirty solution. Theres no reason why the URL of a report should change should it?

 

Hum not sure I understand the use case.  Would you please explain your process?  If you need to create a button on a cert CI to create a task that is definitely doable.  I am not following how the report fits into all of this.

We currently have a scheduled weekly task which tells the analyst to go to Reports in ServiceNow and run the cert expiry report which reports all cert CIs which are due to expire. They then chase up the support groups who own these certs to renew them.

What I would like to do if streamline the process and get the report to automatically run so they don't need to run it manually, but they need to be able to view the report in ServiceNow as the cert names link to their CIs and the analyst will be able to view work notes and related tasks to find out what is happening so they can chase up the correct team with the most up to date information.

The only way I can think to do this is by adding the URL of the report to the scheduled task so all they have to do is copy and paste the URL rather than take the time to find the correct report in View/Run