How to copy choice list values from one field to another field

Hareesha
Tera Contributor

I have 2 fields which are of choice list, Now requirement is to copy one field values to another field and also by eliminating duplicates.

2 ACCEPTED SOLUTIONS

Nayan  Dhamane
Kilo Sage
Kilo Sage

Hello @Hareesha,

Please run this script in your background script:

 

var project = new GlideRecord('your table name');

project.addNotNullQuery('second field'); //query to check if the second field has empty value

project.query();

while (project.next())

{

project.second field = project.first field;

project.update();

}

 

Please mark it as correct based on impact.
BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

View solution in original post

Hello,

 

Please use the below script in background or fix script. I have already tried on my PDI works fine. Correctly replace the fieldname. Assuming you will copy values from fieldname1 to fieldname2. Also I hope fieldname1 and fieldname2 are referring to the same table

 

var gr = new GlideRecord('pm_project');
gr.addEncodedQuery('addyourquery');
gr.query();
while (gr.next()) {
var value = [];
value = gr.replacefieldname1.split(',');
value.push(gr.replacefieldname2.split(','));
var uniqueValue = new ArrayUtil().unique(value);
gr.replacefieldname2 = uniqueValue.toString();
gr.update();
}

 

Please mark my answer as correct based on Impact.

View solution in original post

8 REPLIES 8

Musab Rasheed
Tera Sage
Tera Sage

Hello,

You can select table and another field like below, it should work easily.

MusabRasheed_0-1669799436481.png

Please hit like and mark my response as correct if that helps
Regards,
Musab

 Hi Rasheed, I can see only one field called choice under choice list specification

Can you share screenshot of your form please ?

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Rasheed my requirement is not to get same field values from another table. My requirement is i have 2 fields in project form and there are some existing records. Now they are asking me to remove one field and copy whatever selected data from dropdown in the field to another field by eliminating duplicates as second field is also having some data. Both fields are of type list and same field values.