Change the field value to empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 08:25 AM
Hi Team,
Need to change the 'Country ' field value to empty. By default the value is updated as USA for all the records.
Please help me with background script.
Regards,
Ashwini Rajendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 04:51 AM - edited 05-18-2024 04:51 AM
Hi @Ashwini R ,
PFB below the script,
var grCountry = new GlideRecord('your_table_name');
grCountry.addQuery('country', 'USA');
grCountry.query();
grCountry.setValue('country', '');
grCountry.updateMultiple();
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 07:10 AM - edited 05-18-2024 07:11 AM
Hi @Ashwini R ,
If the country field is of type 'string' with choices then you cannot set it to empty rather you have to select any one of the choices.
In the Country field, you can go the dictionary entry and in the choice list specification, you can selected drop down with none and then set the values to none.
The code will be as below:
var updateCountry = new GlideRecord('your_table_name'); //Replace with your table name
updateCountry.addEncodedQuery("country=USA"); //Replace the encoded query according to your field values
updateCountry.query();
while(updateCountry.next()){
updateCountry.setValue('country', '');
updateCountry.setWorkflow(false);
updateCountry.update();
}
Please mark this response as correct or helpful if it assisted you with your question.
Mark this as Helpful / Accept the Solution if this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 10:01 AM - edited 05-18-2024 10:04 AM
Hi @Ashwini R ,
Please try below script
var gr = new GlideRecord('your_table_name'); //Your table name
gr.addQuery("country", "USA");
gr.query();
while(gr.next()){
gr.setValue('country', ''); // To empty
gr.update();
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak