Update all records. Can you update a field to empty?

dartx21
Kilo Contributor

Hi All,

I am trying to update a reference field to empty for all records.

I tried filtering and update all on those records to make the reference field empty.

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Hi Chris,



Have you tried this



gr.assigned_to = "";



Re: Updating reference fields with 'NULL'



Regards,


Harshvardhan


View solution in original post

9 REPLIES 9

Harsh Vardhan
Giga Patron

Hi Chris,



Have you tried this



gr.assigned_to = "";



Re: Updating reference fields with 'NULL'



Regards,


Harshvardhan


ramireddy
Mega Guru

you can just set that field to empty. Here is an example.



var gr = new GlideRecord('u_referencetable');


gr.query();


while(gr.next())


{


  gr.u_maintableid = "";


  gr.update();


}


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Chris,



What about an update via a GlideRecord?



var gr = new GlideRecord('incident');


gr.addQuery(<your conditions here>);


gr.query();



while(gr.next()){


        //set opened_by to empty value


        gr.opened_by = '';


        gr.update()


}



Regards,


Thanks! Just update 7K+ records in minutes.

var grp = new GlideRecord('sys_user_group');\\table of focus
grp.addEncodedQuery('active=true^type=4b9b46ba1bb39010a4a32f0b234bcb71');\\condition. group IS active AND group TYPE is = enter type sys ID
grp.query();
while(grp.next())
{
grp.type ='';\\updates field TYPE that equals "4b9b46ba1bb39010a4a32f0b234bcb71" to null/empty
grp.update();
}

 

 

4yrs from the future i thank you again.