Create a new child incident from parent incident

Tharun15
Tera Contributor

Please find the below code 
i tried this code but wont' work  

var incident = new GlideRecord("incident");

//change.short_description = current.short_description;
incident.initialize();
incident.short_description = current.short_description;
incident.description = current.description;
incident.cmdb_ci = current.cmdb_ci;
incident.priority = current.priority;
incident.caller_id = current.requested_for;
incident.opened_by = current.opened_by;

var sysID = incident.insert();
var mySysID = current.update();
gs.addInfoMessage("incident " + incident.number + " created");

//function onCreateChildIncident(){
//NOW._createChildIncident(g_form.getUniqueValue());
//}
//current.sc_req_item_state = State.cancel;

current.update();

current.cancel_sc_req_item = gs.getUserID();
//gs.addInfoMessage("incident" + incident.number + "has been created" );

action.setRedirectURL(current);

//action.setReturnURL(current);

If i click on create a incident then child incident should be updated into below child incident table 

find_real_file.png


find_real_file.png

1 ACCEPTED SOLUTION

palmen
Tera Guru

This should probably work, note that there are 2 different parent fields on incident table, either parent or parent incident. It seems like you are displaying the Parent Incident related list so that's the field you need to set on the child incident.

You had 2 current.update() in your code which isn't needed, and the two variables you set wasn't used so I removed them. not sure what the current.cancel_sc_req_item does in the code but I left it there since you had it. But it should probably not be there.

var incident = new GlideRecord("incident");
incident.initialize();
incident.short_description = current.short_description;
incident.description = current.description;
incident.cmdb_ci = current.cmdb_ci;
incident.priority = current.priority;
incident.caller_id = current.requested_for;
incident.opened_by = current.opened_by;
incident.parent_incident = current.getUniqueValue(); //This is what add the parent relation to the current record.

var sysID = incident.insert();
gs.addInfoMessage("Incident " + incident.number + " created");

current.cancel_sc_req_item = gs.getUserID();
current.update();

action.setRedirectURL(current);

Please mark as Helpful/Correct if this helps or solve the problem.

View solution in original post

8 REPLIES 8

Allen Andreas
Administrator
Administrator

Please add this:

incident.parent = current.sys_id;

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you


Please send detail

This is not working 

 

Thanks,

Kumar

Try this is working for me

 

var incident = new GlideRecord("incident");
incident.initialize();
incident.short_description = current.short_description;
incident.description = current.description;
incident.cmdb_ci = current.cmdb_ci;
incident.priority = current.priority;
incident.caller_id = current.requested_for;
incident.opened_by = current.opened_by;
incident.parent_incident = current.sys_id;
incident.insert();
action.setRedirectURL(current);

 

Mark as correct or helpful based on the impact.

 

Thanks,