Copy Related List to New Record in a different table (change_request)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2019 07:17 PM
Hi all,
I am trying to create a UI Action that will copy a record from a table [rm_release] to a new Change Request [change_request]. I am copying over the values of some fields, copying the 'Affected CIs' over, and would like to copy over the other related lists.
The related lists from the original record are:
- Release Task->Parent
- Approvers
- Affect CIs
- Incident->Pending Release
- Request->Pending Release
- Problem->Pending Release
The related list from the target record are:
- Change Task->Change request
- Approvers
- Change Request->Parent
- Affected CIs
- Conflict->Record
- Incident->Caused by Change
- Incident->Pending Change
- Problem->Failed Change
Currently it all works (Even copying the Affected CI's over), except for the following:
- The related lists do not copy over
- After the record is created I would like it to redirect to the newly created Change record
- There is a field on the original record on the [rm_release] table called 'Related Change' [u_reference_3] that I would like to set to the 'Number'[number] of the newly created Change record
The UI Action Script is as below:
//create a new Release record and populate fields
var newchange = new GlideRecord('change_request');
var myUserObject = gs.getUserID();
newchange.initialize();
//Fields copied to new Change record
newchange.assignment_group = current.assignment_group;
newchange.assigned_to = myUserObject;
newchange.type = "emergency";
newchange.short_description = current.short_description;
newchange.assignment_group = current.assignment_group;
newchange.assignment_group = current.assignment_group;
newchange.category = current.u_choice_2;
newchange.business_service = current.u_reference_2;
newchange.assigned_to = current.assigned_to;
newchange.justification = current.description;
newchange.u_initiative_reference = current.number;
newchange.description = current.u_string_3;
//copy list of Affected CI's
var oldid = current.sys_id.toString();
var newid = newchange.insert();
if (newid) {
var taskcis = new GlideRecord('task_ci');
taskcis.addQuery('task',oldid);
taskcis.query();
while (taskcis.next()) {
taskcis.task = newid;
taskcis.insert();
}
}
gs.addInfoMessage("Change " + newchange.getValue("number") + " created");
action.setReturnURL(current);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2019 07:23 PM
1) copy data from table based on relationship.
2)use action.setRedirectURL (newchange) for redirection
3) add below in UI action
current.u_reference_3=newchange;
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2019 08:36 PM
Hi Ankush,
2) and 3) work now but I don't understand what you mean for
1). Can you elaborate?
Best regards,
Luke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2019 09:00 PM
Hi Luke,
For related list to be also same you need to make Glide record query to target table and insert data or relationship.
- Approvers (use workflow to generate approvals)
- Affect CIs (insert data in task_ci with ci_item =current.ci and task as current.sys_id)
Thanks
Ankush