Getting error org.mozilla.javascript.NativeArray

Community Alums
Not applicable

I have a requirement where I want to fetch all the computer names from cmdb_ci_computer table that are assigned to requester and also want to set the field with newly assigned computer.

there is existing script include as well as catalog client script  but when I used array it throws the error org.mozilla.javascript.NativeArray 

Please suggest ,what is going wrong here 

Catalog client script:- 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var ga = new GlideAjax('PL4UserServiceAjax');
    ga.addParam('sysparm_name', 'getUserComputer');
    ga.addParam('sysparm_user', newValue);
    ga.getXMLAnswer(setComputer);
}

function setComputer(response){
    g_form.setValue('Computername', response);

}

Script include :- 

getUserComputer: function(userId) {
        var host =[];
        var comp = new GlideRecord("cmdb_ci_computer");
        comp.addQuery("assigned_to", userId);
    //    comp.orderByDesc("sys_created_on");
        comp.query();
        while (comp.next()) {
            var str = (comp.getValue("name"));
            host.push(str);
        }     
        return host;
    },

Reference Qualifier:-assigned_to=gs.getUserID()^install_status!=7^sys_class_name=cmdb_ci_computer^EQ

Default Value:- javascript: new PL4UserService().getUserComputer(gs.getUserID())

16 REPLIES 16

Hi,

then you need to debug the other script include which is getting called from the main script include

Regards
Ankur

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

Community Alums
Not applicable

Hi Ankur,

In that script only these three lines are there

getUserComputer: function(){
        var computerID;
        var userId = this.getParameter("sysparm_user");
        var computer = new PL4UserService().getUserComputer(userId);           
   

Hi,

then you need to debug this script include and function

        var computer = new PL4UserService().getUserComputer(userId);           

regards
Ankur

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

Community Alums
Not applicable

Hi 

 PL4UserService() is script include with the below code

getUserComputer: function() {
    var host = [];
    var userId = this.getParameter('sysparm_user');
    var comp = new GlideRecord("cmdb_ci_computer");
    comp.addQuery("assigned_to", userId);
    comp.orderByDesc("sys_created_on");
    comp.query();
    while (comp.next()) {
        var str = comp.getValue("name");
        host.push(str);
    }
    
    var arrayUtil = new global.ArrayUtil();
    host = arrayUtil.unique(host);
    
    return host.toString();
},

Hi Ankur,

Hope you can help. Trying to apply your code above (not as a function) in a dynamic content block. I want the service offering names pushed to an array and then display the array items as a string and display. Below is my code so far.

 

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
var missedSLA = [];
var saMissedSLA = new GlideAggregate('service_availability');
saMissedSLA.addQuery('startONThis month@javascript&colon;gs.beginningOfThisMonth()@javascript&colon;gs.endOfThisMonth()');
saMissedSLA.addQuery('met_commitment', 'false');
saMissedSLA.addQuery('type', 'monthly');

 

saMissedSLA.query();
while (saMissedSLA.next()){
    missedSLA.push(saMissedSLA.service_offering.getDisplayValue());
}
var arrayUtil = new global.ArrayUtil();
missedSLA = arrayUtil.unique(missedSLA);
missedSLA.toString();
missedSLA;    
</g:evaluate>
Missed SLA: ${missedSLA;}
</j:jelly>
 
This returns the following in the content block
A service offering has missed its SLA so I should see
Missed SLA: [Service Offering Name here]
 
Can you help with this?
 
I would also like to make it smarter so the result returns Missed SLA: 0 if the array is empty
or
Missed SLA: the array values here i.e. service offering name1, service offering name2 if the array is not empty