- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 10:44 AM
I found this script that copies any uploaded photo in the sys_user table to Live_profile table 'photo' column. I would like to do the reverse.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var livetable=new GlideRecord('live_profile');
livetable.addQuery('document',current.sys_id);
livetable.query();
while(livetable.next())
{
livetable.photo=current.photo;
livetable.update();
}
})(current, previous);
Here is my current script performed on the Live_profile table.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var photo=current.photo.getDisplayValue();
//gs.addInfoMessage(photo);
var gr=new GlideRecord('sys_user');
gr.addNullQuery('photo');
//gr.addQuery('photo', current.sys_user.photo);
gr.query();
if(gr.next())
{
// gs.addInfoMessage(gr.photo);
gr.photo.setValue(photo);
gr.update();
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 05:59 AM
Hiya. Run this script in Scripts - Background:
var profileUser = new GlideRecord('live_profile');
profileUser.addNotNullQuery('photo');
profileUser.addQuery('type','user');
profileUser.query();
while(profileUser.next()) {
var userUser = new GlideRecord('sys_user');
userUser.addQuery('sys_id',profileUser.document); // match the users
userUser.query();
if(userUser.next()){
userUser.setValue('photo',profileUser.photo);
userUser.update();
}
}
I've tested it in my dev instance and it works fine:
Some users appear to have photos but the photo field is empty. I'm not sure why this is but those photos won't get copied across.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 11:50 AM
Try the below
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr=new GlideRecord('sys_user');
gr.addNullQuery('photo');
gr.addQuery('sys_id', current.getValue('document'));
gr.query();
if(gr.next())
{
gr.setValue('photo', current.getValue('photo'));
gr.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 12:12 PM
Sorry. That didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 02:06 PM
Ok. Kept trying and it seemed like it did it once, but then hasn't since.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2022 04:05 PM
I believe it should be a while loop, not an if:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr=new GlideRecord('sys_user');
gr.addNullQuery('photo');
gr.addQuery('sys_id', current.getValue('document'));
gr.query();
while (gr.next())
{
gr.setValue('photo', current.getValue('photo'));
gr.update();
}
})(current, previous);