- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 12:23 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 06:48 AM
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
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 07:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 04:09 AM
Hello,
Please share screenshot so it would be easier to assis you.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 06:26 AM
Hi Saurav 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 data is in the field to another field by eliminating duplicates. Both fields are of type list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 07:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 06:48 AM
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
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.