Change the field value to empty

Ashwini R
Tera Contributor

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.

 

AshwiniR_0-1715873065188.png

Regards,

Ashwini Rajendra

3 REPLIES 3

Amitoj Wadhera
Kilo Sage

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

SN_Learn
Kilo Patron
Kilo Patron

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.

 

SN_Learn_0-1716040871740.png

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.

Community Alums
Not applicable

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