- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 02:55 AM
Hi, I have a requirement where one field for example 'Client_impact' has 5 choices and the field is string field. Recently we have made all the choices inactive and created two new choices for the field. Now the requestor want to update all the historical tickets with 2 new choices. First inactive option should match 1st active new option and all other four inactive options should match 2nd active new option. Field is on the table TMI_INCIDENT table. Can someone help me with the Fix script to update all the records. Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 03:22 AM
Hi,
Try below code
// Query for the historical tickets
var incidentGr = new GlideRecord('incident');
incidentGr.addActiveQuery(); // Add any additional filters if required
incidentGr.query();
// Update the Client_impact field for historical tickets
while (incidentGr.next()) {
var clientImpact = incidentGr.getValue('client_impact');
// Map the old inactive options to the new active options
if (clientImpact == 'Inactive Option 1') {
incidentGr.setValue('client_impact', 'New Active Option 1');
} else if (clientImpact == 'Inactive Option 2' || clientImpact == 'Inactive Option 3' || clientImpact == 'Inactive Option 4' || clientImpact == 'Inactive Option 5') {
incidentGr.setValue('client_impact', 'New Active Option 2');
}
incidentGr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 03:22 AM
Hi,
Try below code
// Query for the historical tickets
var incidentGr = new GlideRecord('incident');
incidentGr.addActiveQuery(); // Add any additional filters if required
incidentGr.query();
// Update the Client_impact field for historical tickets
while (incidentGr.next()) {
var clientImpact = incidentGr.getValue('client_impact');
// Map the old inactive options to the new active options
if (clientImpact == 'Inactive Option 1') {
incidentGr.setValue('client_impact', 'New Active Option 1');
} else if (clientImpact == 'Inactive Option 2' || clientImpact == 'Inactive Option 3' || clientImpact == 'Inactive Option 4' || clientImpact == 'Inactive Option 5') {
incidentGr.setValue('client_impact', 'New Active Option 2');
}
incidentGr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 05:06 AM
Hi Rahul, Thanks for the reply and as per the above code you have mentioned it's querying all the active tickets. In my case i have to update all the tickets including closed and cancelled ones for better reporting. Can u suggest what to write instead of addActiveQuery method?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 05:41 AM
-Fix script can be used to update inactive old choices with New choices in all the records
-The script should include a function to identify the inactive old choices
-The script should include a function to replace the inactive old choices with the new choices
-The script should include a loop to iterate through all the records
-The script should include a commitment to save the changes to the database
For asking ServiceNow-related questions try this :
For a good and optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 06:25 AM
Remove that line and try