"I'm Affected Too" button from System Status v2 and users with no role.

Luiz Lucena
Mega Sage

Hello everyone, 
We are adding the awesome System Status v2 found in the Share portal and developed by Andrew Albury-Dor and we noticed that users without a role, when clicking the button I'm Affected Too in the Current Status widget, the incident created on their behalf by the widget doesn't populate the category and subcategory. 
Users with ITIL role however, when clicking that button, the Category and Subcategory are populated correctly. 
Anyone has any idea how to fix that?
Here is the part of the code that creates the incident.

if (input && input.action == 'create_incident') {
	
	var incidentGr = new GlideRecord('incident');
	incidentGr.short_description = "I'm affected by outage: " + input.outage.typeDisplay + ": " + input.outage.ci;
	incidentGr.description = incidentGr.short_description;
	incidentGr.caller_id = gs.getUserID();
	incidentGr.u_on_behalf_of = gs.getUserID();
	incidentGr.business_service = input.outage.serviceID;
	incidentGr.cmdb_ci = input.outage.serviceID;
	if (input.outage.task_type.indexOf("INC") != -1) {
		incidentGr.parent = input.outage.taskid;
		incidentGr.category = input.outage.category;
		incidentGr.subcategory = input.outage.subcategory;
		incidentGr.assignment_group = input.outage.taskid.assignment_group;
		incidentGr.contact_type = 'self-service';
	} else if (input.outage.task_type.indexOf("PRB") != -1) {
		incidentGr.problem_id = input.outage.taskid;
	} else if (input.outage.task_type.indexOf("CHG") != -1) {
		incidentGr.caused_by = input.outage.taskid;
	}
	incidentGr.state = 2;
	var incidentSysId = incidentGr.insert();
	
	data.incident_number = incidentGr.getValue('number');

	var taskOutageGr = new GlideRecord('task_outage');
	taskOutageGr.task = incidentSysId;
	taskOutageGr.outage = input.outage.sys_id;
	taskOutageGr.insert();
	
	data.response = gs.getMessage('Incident ' + incidentGr.getValue("number") + ' submitted.');
	data.response_link = '?view=sp&id=ticket&table=incident&sys_id=' + incidentGr.getValue("sys_id")
	
	data.action = '';
	data.outage = '';
}

 

And the full server script below:

// populate the 'data' object
// e.g., data.table = $sp.getValue('table');
var outage = new GlideRecord("cmdb_ci_outage");
outage.addQuery("cmdb_ci.sys_class_name", "cmdb_ci_service");
outage.addQuery("begin", "<=", new GlideDateTime().getValue());
outage.addQuery("end", ">=", new GlideDateTime().getValue()).addOrCondition("end", "=", "NULL");
outage.orderByDesc("type");
if (options.num_to_show) {
	outage.setLimit(options.num_to_show);
}
data.service = (input && input.service) || $sp.getParameter("service");
if (data.service) {
  outage.addQuery("cmdb_ci", data.service);
	var serviceGR = new GlideRecord("cmdb_ci_service");
	if (serviceGR.get(data.service))
		data.serviceDisplay = serviceGR.getDisplayValue();
}
outage.query();
data.outages = [];
data.outageIDs = "";
while (outage.next()) {
	var out = {};
	out.typeDisplay = outage.type.getDisplayValue();
	out.type = outage.getValue("type");
	out.details = outage.getValue("details");
	out.ci = outage.cmdb_ci.getDisplayValue();
	out.sys_id = outage.getUniqueValue();
	out.taskid = outage.getValue("task_number");
	out.task_type = outage.getDisplayValue("task_number");
	out.serviceID = outage.getValue("cmdb_ci");
	
	var tsknumGr = new GlideRecord("incident");
	tsknumGr.get(out.taskid);
	
	out.category = tsknumGr.getValue("category");
	out.subcategory = tsknumGr.getValue("subcategory");
	
	out.begin = outage.begin.getDisplayValue();
	
	var loggedIncGr = new GlideRecord('task_outage');
	loggedIncGr.addEncodedQuery("task.numberSTARTSWITHINC^task.opened_by=" + gs.getUserID() + "^outage=" + outage.getUniqueValue());
	loggedIncGr.query();
	
	var hasInc = loggedIncGr.next();
	out.incident_number = hasInc ? loggedIncGr.task.getDisplayValue() : false;
	out.incident_sys_id = hasInc ? loggedIncGr.getValue('task') : false;
	
	data.outages.push(out);
	data.outageIDs += "," + outage.getUniqueValue();
}

if (input && input.action == 'create_incident') {
	
	var incidentGr = new GlideRecord('incident');
	incidentGr.short_description = "I'm affected by outage: " + input.outage.typeDisplay + ": " + input.outage.ci;
	incidentGr.description = incidentGr.short_description;
	incidentGr.caller_id = gs.getUserID();
	incidentGr.u_on_behalf_of = gs.getUserID();
	incidentGr.business_service = input.outage.serviceID;
	incidentGr.cmdb_ci = input.outage.serviceID;
	if (input.outage.task_type.indexOf("INC") != -1) {
		incidentGr.parent = input.outage.taskid;
		incidentGr.category = input.outage.category;
		incidentGr.subcategory = input.outage.subcategory;
		incidentGr.assignment_group = input.outage.taskid.assignment_group;
		incidentGr.contact_type = 'self-service';
	} else if (input.outage.task_type.indexOf("PRB") != -1) {
		incidentGr.problem_id = input.outage.taskid;
	} else if (input.outage.task_type.indexOf("CHG") != -1) {
		incidentGr.caused_by = input.outage.taskid;
	}
	incidentGr.state = 2;
	var incidentSysId = incidentGr.insert();
	
	data.incident_number = incidentGr.getValue('number');

	var taskOutageGr = new GlideRecord('task_outage');
	taskOutageGr.task = incidentSysId;
	taskOutageGr.outage = input.outage.sys_id;
	taskOutageGr.insert();
	
	data.response = gs.getMessage('Incident ' + incidentGr.getValue("number") + ' submitted.');
	data.response_link = '?view=sp&id=ticket&table=incident&sys_id=' + incidentGr.getValue("sys_id")
	
	data.action = '';
	data.outage = '';
}
1 ACCEPTED SOLUTION

Moedeb
Tera Guru

@Luiz Lucena here is the solution that we went with. It is a flow that is triggered whenever an incident is created from the system status page - "I'm affected" button.

I have attached a pdf that shows the entire flow in a visual method so someone can recreate it if they like with their own updates/edits and as an update set that will add the flow as is.

 

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, have you tried enabling security debug, impersonating an impacted (non rolled) user and then reviewed the ACL debug logs to ensure that your user has rights to read the source field\record and write to the target record\field.

ACL debugging tools (servicenow.com)

Hi @Tony Chatfield1 

Yes, nothing comes up regarding Category or Subcategory. 
We have a record producer which creates Incident from the Service Portal as well, incidents created by users without ITIL role generates the incident without any issue, including category, subcategory, etc. 

Only this widget is not working fine.

Hi, perhaps a visibility\ACL issue as the user is indirectly accessing these 'task' fields, and while in a record producer these may be populated in the producer script or from the producers variables, this functionality makes a lookup of the reference task.

Moedeb
Tera Guru

@Luiz Lucena here is the solution that we went with. It is a flow that is triggered whenever an incident is created from the system status page - "I'm affected" button.

I have attached a pdf that shows the entire flow in a visual method so someone can recreate it if they like with their own updates/edits and as an update set that will add the flow as is.