The CreatorCon Call for Content is officially open! Get started here.

Getting org.mozilla.javascript.NativeArray@79343f70 Error

preethigovi
Tera Contributor

Hi Team,

Iam running fix script to get the details of manager from HR profile and set it to journey table.

While running iam getting org.mozilla.javascript.NativeArray@79343f70 as log Any suggestion?

Fix script:

var emplye = [];
var empData = new GlideRecord('sn_jny_journey');
empData.addEncodedQuery('numberINJNY00002061,JNY00002062');
empData.query();
while (empData.next())
    emplye.push(empData.employee.sys_id);
gs.info('PTEST1' + emplye);



var user = new sn_hr_core.getHiredate().getManager(emplye);
gs.info('PTEST2' + user)
var managerUpdate = new GlideRecord('sn_jny_journey');
managerUpdate.addEncodedQuery('numberINJNY00002061,JNY00002062');
managerUpdate.query();
while (managerUpdate.next()) {
    managerUpdate.manager = user;
    gs.info('PTEST4' + managerUpdate.manager)
    managerUpdate.update();

}
 
Script include:
getManager: function(emplye) {
        var managers = [];
        var hrProfileGR = new GlideRecord('sn_hr_core_profile');
        hrProfileGR.addQuery('sys_idIN' + emplye);
        hrProfileGR.query();
        while (hrProfileGR.next()) {
            var managerValue = hrProfileGR.getDisplayValue('user.manager.sys_id');
            if (managerValue) {
                gs.info('Manager Sys_ID: ' + managerValue);
                managers.push(managerValue.toString());
            }

        }

        return managers;
preethigovi_0-1734609208241.png

 

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

You need to always force a sys_id to a string when pushing it to an array, or you will get an array of the same sys_id / unexpected results.

    emplye.push(empData.employee.toString());

This may not matter, but it's also best to specify the join of an array rather than leave it to the default:

var user = new sn_hr_core.getHiredate().getManager(emplye.join(','));

You should also use {} with your first while statement for clarity. Just as the first sys_id example, when a field has a table that is a reference, just use the field name to get the sys_id, you don't need/want to dot-walk to the sys_id field:

            var managerValue = hrProfileGR.getDisplayValue('user.manager');

I don't have this table, but is the manager field capable to receive a long text string?

Ankur Bawiskar
Tera Patron
Tera Patron

@preethigovi 

what's your business requirement here? I could see you want to update manager on HR profile but you are setting array in string field

 

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

preethigovi
Tera Contributor

@Brad Bowman  @Ankur Bawiskar ,

I made the changes and added extra 

managerUpdate.manager = user.toString(); so it returned manager name in log.
But in Journey table, in xml it shows manager sys_id, but no display value in journey owner field.

preethigovi_0-1734614179020.png

 

@preethigovi 

are you sure manager field in your table is reference to sys_user?

if yes then it should work

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