Create Defect from Incident - Cannot find a related list that will display the incident on the defect form

Brendan Hallida
Kilo Guru

Hi there,

I have a create defect UI action that created a defect from the Incident.  Code is below:

createDefect();

function createDefect() {
	var task = new GlideRecord("rm_defect");
	task.short_description = current.short_description;
	task.description = current.description;
	task.priority = current.priority;
	task.parent = current.sys_id;
	var taskSys = task.insert();
	
	//Insert relationship
	var rel = new GlideRecord('task_rel_task');
	rel.parent = current.sys_id;
	rel.child = taskSys;
	rel.type.setDisplayValue('Solved by::Solves');
	rel.insert();
	
	//gs.addInfoMessage(gs.Message("Defect {0} created",task.number));
		action.setRedirectURL(task);
		action.setReturnURL(current);
	}

This creates the defect and sets the parent as the incident the defect was just raised from.  This means when I add the related list Defect > Parent on the incident form I can see the defect that was just raised.

that is all working well, however, when I go to the defect form, I am not sure what related list I should be using.  I found this post; https://community.servicenow.com/community?id=community_question&sys_id=9a0601dddb09db04032a7a9e0f96... where Sanjiv mentions to use  Defect -> Incident related list, however, in our instance (and my personal developer instance) this does not exist. 

find_real_file.png

I have also tried creating my own relationship, however, I cannot get that working either.

find_real_file.pngDoes anyone know what I am missing here?

TIA!

1 ACCEPTED SOLUTION

Inactive_Us1180
Kilo Guru

Thy this in your relationship record.

 

(function refineQuery(current, parent) {

var inc = parent.parent.sys_id;
current.addQuery('sys_id',inc);

})(current, parent);

 

View solution in original post

3 REPLIES 3

Mark Skinner
Mega Guru

Hi,

I have had the requirement to create a similar thing to you.

 

on your incident you can create an UI action with the following code.

 

createOutageM2M();

function createOutageM2M() {

  //Update saves incidents before going to the catalog homepage
  current.update();
  gs.addInfoMessage(gs.getMessage('You will need to navigate back to {0} upon completion', current.number + ""));

  var outage = new GlideRecord("cmdb_ci_outage");
  outage.cmdb_ci = current.cmdb_ci;
  outage.task_number = current.sys_id;
  var outageID = outage.insert();

  var task_outage = new GlideRecord('task_outage');
  task_outage.task = current.sys_id;
  task_outage.outage = outageID;
  task_outage.insert();

  action.setRedirectURL(outage);
  action.setReturnURL(current);
}

 

If this has been helpful could you please mark as so. If this solved your issue can you mark as answered.

 

Inactive_Us1180
Kilo Guru

Thy this in your relationship record.

 

(function refineQuery(current, parent) {

var inc = parent.parent.sys_id;
current.addQuery('sys_id',inc);

})(current, parent);

 

You Rock!

That worked a treat!

Thanks, appreciate your help 🙂