- 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
12-13-2023 02:49 PM - edited 12-17-2023 11:59 AM
I started concentrating on this specifically because I need it for my job. I found christopher occhicone information for my project. This is the most important stage, in my opinion, because locating the right materials is essential to the project's future success.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2022 06:22 AM
Just in case anyone needs a full recap on this.
Run on table: Live_profile
When to run: After, Insert and Update "checked".
Filter Conditions: Photo changes
Advanced script with script below.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
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();
}
}
})(current, previous);