Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to delete photo for all users in the system

Alon Grod
Tera Expert

Hi,

How can I delete the image from the 'photo' field on the sys_user table for all users in the system using a Fix script?

1 ACCEPTED SOLUTION

@Alon Grod 

 

I can see records are going to the sys_attachment table, if you delete from there it would be automatically remove from users table

 

here is the script, before executing the script please try it for single record:

 

var gr = new GlideRecord("sys_attachment");

gr.addEncodedQuery("table_name=ZZ_YYsys_user");

gr.setLimit(1); //remove this for all the records

gr.query();

while(gr.next()){

    gr.deleteRecord();

}

PrinceArora_0-1690915149988.png

 

I hope you will get an idea!

 

 

View solution in original post

5 REPLIES 5

Tushar
Kilo Sage
Kilo Sage

Hi @Alon Grod 

 

This code should iterate through all records in the sys_user table, check if the photo field has an attachment, and if so, delete the attachment (photo) using the deleteRecord() method.

 

 

 

function deletePhotoField(user) {
  var photo = user.getPhoto();
  if (photo) {
    photo.deleteRecord();
  }
}

var users = new GlideRecord('sys_user');
users.query();
while (users.next()) {
  deletePhotoField(users);
}

 

 

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

Alon Grod
Tera Expert

@Tushar  its not working

Alon Grod
Tera Expert

@Alon Grod 

 

I can see records are going to the sys_attachment table, if you delete from there it would be automatically remove from users table

 

here is the script, before executing the script please try it for single record:

 

var gr = new GlideRecord("sys_attachment");

gr.addEncodedQuery("table_name=ZZ_YYsys_user");

gr.setLimit(1); //remove this for all the records

gr.query();

while(gr.next()){

    gr.deleteRecord();

}

PrinceArora_0-1690915149988.png

 

I hope you will get an idea!