- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 10:24 AM
One variable - business_unit(Choice- X,Y,Z,A,B,C)
Another variable- impacted_business_unit (reference to business_unit variable)
Requirement : To map the impacted_business_value for all the records(1000s) with below mentioned conditions :
1. All the records with choice X & Y Selected in Impacted business unit, it should be changed to Choice A.
2. All the records with choice Z & C selected in Impacted business unit, it should be changed to Choice B.
Any help on this would be highly appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2023 07:43 AM - edited 10-19-2023 07:44 AM
Hi @developersn,
Please confirm if that business_unit & impacted_business_unit both are mapped in some custom table or its just value in record table like incident.
If this mapping is already configured in some table ( either system table or custom ) then go with fix script code, here some of our friends already shared the code snippet logic try that.
In case, you have any issue please share the mapping table details and fix script code you are writing so we can debug the issue.
Suggestion : Code the fix script and run it for few record only , once test pass then go for all records.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 09:58 PM
Hi @developersn
You can write a Fix script to update the records :
/*1. Glide record on your table*/
var gr = new GlideRecord('your_table_name');
gr.addEncodedQuery('business_unit=X^ORbusiness_unit=Y' ); // query with business unit
gr.query();
while(gr.next()){
/*2. Update the record with desired business unit*/
gr.your_field_name = 'A';
gr.update();
}
//You can use same logic for other business unit
Hope this helps...!!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 11:04 PM
Hi @developersn ,
Write fix script
var incidentRecord = new GlideRecord("table");
incidentRecord.query();
while (incidentRecord.next()) {
var businessUnit = incidentRecord.business_unit;
if ((businessUnit == 'X' || businessUnit == 'Y') {
incidentRecord.impacted_business_unit = 'A';
} else if ((businessUnit == 'Z' || businessUnit == 'C') {
incidentRecord.impacted_business_unit = 'B';
}
incidentRecord.update();
}
Thanks,
Anand