How to update Live_profile photo field with sys_user's avatar/photo?

Divi
Mega Guru

Hi all,

How to update Live_profile photo field with sys_user's avatar/photo?My requirement is to update the photo field of live_profile table using the sys_user's photo/avatar.I tried using the background script :

var user= new GlideRecord('sys_user');

var photo= user.photo;

user.addQuery('photo','!=','');

 

user.query();

while(user.next())

{

user.avatar=photo;

user.update();

var live = new GlideRecord('live_profile');

 

live.addQuery('document',user.sys_id);

live.query();

while(live.next())

{

live.photo=user.photo;

gs.print('number'+ live.getRowCount());

 

live.update();

 

}

 

 

But the live_profile table is not showing the photos but sys_id is generated and showing updated by "my id".Can anyone help me out on this scenario..

Thanks.

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

I updated your code a bit. Could you test this? Also added a setLimit(5) for testing purposes.

var user = new GlideRecord('sys_user');
user.addNotNullQuery('photo');
user.setLimit(5);
user.query();

while(user.next()) {
	var live = new GlideRecord('live_profile');
	live.addQuery('document', user.getUniqueValue());
	live.query();

	if(live.next()) {
		live.photo = user.getValue('photo');
		live.update();
	}
}

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

Thanks for the reply, I tried the code but still i'm unable to see photo in the live_profile table..

find_real_file.png

have fetched the sys_id of updated profile, you can refer the screenshot-->photo is still not visible 

Hmm interesting. I tried the code on my PDI, works instantly.

Can you verify if for those records, the sys_id is filled? Though the photo is not displayed? Or is the sys_id already not filled in the photo field? Asking because I don't see a updated date in your picture

For the users you are after, can you verify that in their user record, there's a sys_id in the photo field? Can you also verify if you can find that sys_id in the sys_attachment table?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

1.sys_id is filled in live_profile table but photo is not displaying on list view as well as form view.

2.user has sys_id of photo in sys_user table also.

3.and yes its sys_id is also there in the sys_attachment table.