Script returns undefined for reference value

preethigovi
Tera Contributor

Hi Team,

I was learning on scripting where i had uses case to fetch manager (reference to user table) in HR profile and populate on filed on other scoped table

 

var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('sys_id=04556f50471f1110e72d7116536d43f9');
hrProfileGR.query();
var managerValue = hrProfileGR.getValue('manager');
var userValue = hrProfileGR.getDisplayValue('user')
gs.info('PreeManager value: ' + managerValue);
gs.info('PreeManager2 value: ' + userValue);
 
Can you point out why its returning null value for managers?
 
preethigovi_0-1733471691042.png

 

1 ACCEPTED SOLUTION

@preethigovi 

use this script

var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.query();
while (hrProfileGR.next()) {
    var userValue = hrProfileGR.getValue("user");
    var userProfile = new GlideRecord('sys_user');
    if (userProfile.get(userValue)) {
        hrProfileGR.u_manager = userProfile.manager;
        hrProfileGR.update();
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

14 REPLIES 14

@Bhavya11 @Abhishek_Thakur  Thank You.

 

I have to convert this script as schedule job and update the manager in HR profile, but for some reason the manager value is captured in logs but updation not happening ? Any reason

hi @preethigovi ,

 

could you please share your script.

 

 

Thanks,

BK

Ankur Bawiskar
Tera Patron
Tera Patron

@preethigovi 

what should be updated in scheduled job?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

preethigovi
Tera Contributor

@Ankur Bawiskar @Bhavya11 

var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('u_manager', ''); // Check where Hiring Manager is empty
hrProfileGR.addQuery('number=HRP3083319');
gs.info('PT1')
hrProfileGR.query();
if (hrProfileGR.next()) {
    {
        gs.info('PT Success')
        var hiringManager = hrProfileGR.getDisplayValue('user.manager'); // Copy the Manager field value
        hrProfileGR.u_manager = hiringManager;
        hrProfileGR.update();
        // hrProfileGR.setValue('u_manager', hiringManager);
        // gs.info('PT1 :' + hiringManager)
        //gs.info('PT2 :' + hrProfileGR.user.manager)
    }
 
In logs all the details are showing up, but update on HR profile is not happening

Hi @preethigovi ,

 

what type of field is u_manager ?

 

Thanks,

BK