Copy Related List to New Record in a different table (change_request)

Luke Dibben1
Kilo Contributor

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:

  1. The related lists do not copy over
  2. After the record is created I would like it to redirect to the newly created Change record
  3. 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);
3 REPLIES 3

Ankush16
Kilo Guru
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();


Hi Ankush,

2) and 3) work now but I don't understand what you mean for

1). Can you elaborate?

 

Best regards,

Luke

Ankush16
Kilo Guru

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