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

Vijendra2
Giga Contributor

What what is I do not have any field in my reference table which has reference to main table. My main table has reference. Related list table has no field by which I can identify. This is my issue.


Sorry for typos please read "What if I do not have any field in my reference table which has reference to main table. My main table has reference but relatedlist table has no reference. Related list table has no field by which I can identify. This is my issue."


If there is no reference to the main table, how is the related list being populated? There has to be some criteria right?


Jehiellb
Giga Contributor

Hi guys,

 

I know this is an old post.. This maybe out of the context but just want ask how can I add all the related records when copying a change? 

currently only Affected CIsImpacted Services/CIs, and Change Tasks are able to be copied over to new change.

find_real_file.png

Any idea how can I achieve this? I tried editing the 'Copy Change' UI Action but I failed, nothing happens.
any suggestions what else should I change to make this work? I'm gonna be honest, I'm not that good when it comes to scripting  BUT I'm trying. Maybe you guys can help me with that too. 🙂

 

Just in case you came across with this question, your help will be much appreciated, Thank you in advance!

Hi...got any help... facing the same issue... Could you please provide with the script here