Catalog Item: Request to Change your profile picture in Servicenow






  1. Create a Catalog item with following variables.
    1. User Name--(reference field of sys_user table)
    2. Attach Image --(UI Macro)
  2. UI Macro Script:
  3. <?xml version="1.0" encoding="utf-8" ?>
    <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <divid id="pc"><span style="text-decoration: color: #800000;"><h3><strong>Please click the below button to attach the Profile Picture </strong></h3></span></divid>
    <div style="text-decoration: color: #800000; font-weight:bold; font-size: larger;">
    <button value="Click to attach the image" onclick="saveCatAttachment(gel('sysparm_item_guid').value, 'sc_cart_item')">Attach Image</button></div>
    </j:jelly>
  4. Catalog Item will looks like below
  1. Create a Requested Item workflow  and select the same workflow in the catalog item form.
  2. RITM workflow will looks like below
  1. Copy paste the following code in Run Script activity of Workflow
    var tt12=new GlideRecord("live_profile");
    tt12.addQuery('document',current.variables.select_user);
    tt12.query();
    if(tt12.next()){
    var tt5=new GlideRecord("sys_attachment");
    tt5.addQuery('table_sys_id',tt12.sys_id);
    tt5.addQuery('table_name','ZZ_YYlive_profile');
    tt5.query();
    if(tt5.next()){
    tt5.deleteRecord();
    }
    var tt1=new GlideRecord("sys_attachment");
    tt1.addQuery('table_sys_id',current.variables.select_user);
    tt1.addQuery('table_name','ZZ_YYsys_user');
    tt1.query();
    if(tt1.next()){
    gs.log("Pp"+tt12.sys_id);
    tt1.deleteRecord();
    var tt3=new GlideRecord("sys_attachment");
    tt3.addQuery('table_sys_id',current.sys_id);
    tt3.query();
    if(tt3.next()){
    tt3.file_name="photo";
    tt3.table_sys_id=current.variables.select_user;
    tt3.table_name="ZZ_YYsys_user";
    tt3.update();
    }
    }else{
    var tt3=new GlideRecord("sys_attachment");
    tt3.addQuery('table_sys_id',current.sys_id);
    tt3.query();
    if(tt3.next()){
    tt3.file_name="photo";
    tt3.table_sys_id=current.variables.select_user;
    tt3.table_name="ZZ_YYsys_user";
    tt3.update();
    }
    }

    }else{
    gs.log("Pp"+current.variables.select_user);
    var tt3=new GlideRecord("sys_attachment");
    tt3.addQuery('table_sys_id',current.sys_id);
    tt3.query();
    if(tt3.next()){
    tt3.file_name="photo";
    tt3.table_sys_id=current.variables.select_user;
    tt3.table_name="ZZ_YYsys_user";
    tt3.update();
    }

    }
    gs.cacheFlush();
  2. Please make sure, when you use this catalog item to change your profile picture, you need to logout and login to reflect the changes.

Comments

Popular posts from this blog