i want to copy the related list from a record to another record in the same table(say change)?

Sharique Azim
Kilo Sage

Hi all,

I was trying to bring all the list of one record to the new record in the same table,Similar to duplicating the record or insert ui action.

But was not able to bring the related lists.

Thanks and Regards,

Shariq

1 ACCEPTED SOLUTION

veena_kvkk88
Mega Guru

Hi Sharique,



I had a similar requirement and worked on it just yesterday. I needed to have a 'Copy' button that creates an exact copy of the record with the created date and time appended to the name, this should also create copies of the records related list. (same records in related list should show up here too, i.e. copies of them)



If this is exactly the same as you want to do, you could use my UI action script modified to suit your instance.



copyFile();



function copyFile(){


  current.u_name = current.u_name + " Copy_[" + gs.nowDateTime() + "]";


  var originalID = current.sys_id + '';


  var copyID = current.insert() + '';



  if(copyID){


  var gr = new GlideRecord('u_RelatedFile'); //replace table name with the table name of your related list


  gr.addQuery('u_file', originalID); //replace field name with the reference field in your related list that points to the main table


  gr.query();


  while(gr.next()){


  gr.u_file = copyID; //replace field name with the reference field in your related list that points to the main table


  gr.insert();


  }


  }


}



P.S. Please hit like, helpful or Correct for my responses as they apply to you


View solution in original post

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Sharique,



Can you please give example on what exactly you are trying to do.


kiara1
Tera Expert

Hi Sharipque,



Do you want to create a UI action similar to "Insert" in order to copy child (related list) records as well as the parent record?



In this case, you need to modify the original script, and add GlideRecord query to copy all child records to new record.


veena_kvkk88
Mega Guru

Hi Sharique,



I had a similar requirement and worked on it just yesterday. I needed to have a 'Copy' button that creates an exact copy of the record with the created date and time appended to the name, this should also create copies of the records related list. (same records in related list should show up here too, i.e. copies of them)



If this is exactly the same as you want to do, you could use my UI action script modified to suit your instance.



copyFile();



function copyFile(){


  current.u_name = current.u_name + " Copy_[" + gs.nowDateTime() + "]";


  var originalID = current.sys_id + '';


  var copyID = current.insert() + '';



  if(copyID){


  var gr = new GlideRecord('u_RelatedFile'); //replace table name with the table name of your related list


  gr.addQuery('u_file', originalID); //replace field name with the reference field in your related list that points to the main table


  gr.query();


  while(gr.next()){


  gr.u_file = copyID; //replace field name with the reference field in your related list that points to the main table


  gr.insert();


  }


  }


}



P.S. Please hit like, helpful or Correct for my responses as they apply to you


Hi How can I copy related list from one table to a different table