How do I map field values from a parent ticket to a new child ticket?

Tyler Michals
Kilo Guru

When I create a new child ticket, I would like some field values from the parent ticket to automatically be populated into the child ticket. How do I achieve this?

1 ACCEPTED SOLUTION

Here is a script from a UI Action which creates a change request from an incident.


It will guide you through the main points of what you want to do.



var change = new GlideRecord("change_request");
//change.short_description = current.short_description;
//change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
var sysID = change.insert();


var mySysID = current.update();


gs.addInfoMessage("Change " + change.number + " created");


var new_relationship = new GlideRecord('task_rel_task');
new_relationship.type = 'd798ba000a2581020048305ef5287403'; //use the sys_id of the relationship type from your instance here
new_relationship.parent = current.sys_id;
new_relationship.child = sysID;
new_relationship.insert();


action.setRedirectURL(change);
action.setReturnURL(current);


View solution in original post

12 REPLIES 12

Rahul Kathuria
Tera Expert

You can modify below business rule as per your field names:


Name: Close and Cascade Comments to Child Tasks


Type: Business Rule


Table: Incident


Description: This example will close and cascade comments to child incidents after the parent has been closed.


Parameters: Run: After insert and update


Script:


Condition:



current.active.changesTo(false)


Script:



cascadeComment();     
function cascadeComment(){    
var cmt = current.comments;
var inc = new GlideRecord("incident");
inc.addQuery("parent", "=", current.sys_id);
inc.query();
while (inc.next()) {
inc.comments = cmt;
inc.incident_state.setValue( 7);
inc.active.setValue(false);
inc.update();
gs.print("Incident " + inc.number + " closed based on closure of incident " + current.number); } }



HugoFirst
Kilo Sage

I want to throw out some issues to consider.


Here's the use case to think about:   A child ticket is created from a parent ticket and then, some time afterwards,   the parent ticket is updated by another user.


This can be critical in the applications that employ the request, requested item, catalog task tables.



In the child ticket, do you want the field to reflect the value in the parent ticket at the time the child was created?


Or do you want the child to show the current value of the field in the parent any time it displays?



If this is the case, rather than copy the value to the child ticket, you could just add the parent's field to the child's form for display.


( for this discussion, I assume you are talking about fields on the tables and not catalog variables )


In the child ticket, I want some fields to reflect the value in the parent ticket at the time the child was created. So I'm thinking I need to create some kind of UI action button called "Create Child Ticket". When you click that button, a new record appears with certain values autopopulated from the parent ticket. I dont know where to begin building this UI Action button


Here is a script from a UI Action which creates a change request from an incident.


It will guide you through the main points of what you want to do.



var change = new GlideRecord("change_request");
//change.short_description = current.short_description;
//change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
var sysID = change.insert();


var mySysID = current.update();


gs.addInfoMessage("Change " + change.number + " created");


var new_relationship = new GlideRecord('task_rel_task');
new_relationship.type = 'd798ba000a2581020048305ef5287403'; //use the sys_id of the relationship type from your instance here
new_relationship.parent = current.sys_id;
new_relationship.child = sysID;
new_relationship.insert();


action.setRedirectURL(change);
action.setReturnURL(current);


I took a look at the "Create Change" UI action in my instance and it differs from the one you provided. I created the following script based off the "Create Change" UI action in my instance.



var clm = new GlideRecord("x_audi2_clm_table");


clm.short_description = current.short_description;


clm.u_agreement = current.u_agreement;


clm.u_carrier = current.u_carrier;


clm.u_account_number = current.u_account_number;


clm.u_monthly_spend = current.u_monthly_spend;


clm.u_reference_number = current.u_reference_number;


clm.u_type = current.u_type;


clm.company = current.company;


clm.sys_domain = current.sys_domain;


clm.number = current.parent;


var sysID = clm.insert();




current.clm_id = sysID;


var mySysID = current.update();




gs.addInfoMessage("Child Ticket " + clm.number + " has been created");


action.setRedirectURL(clm);


action.setReturnURL(current);



This script creates a new "CLM" record with all the fields mapped, but it does not create that parent/child relationship. I copied and pasted the "new relationship" portion of the your script, and that doesnt work either. Thoughts?