J2js - j2js(Object javaObject)

Convert a java object from system code to a JavaScript object.

Table 1. Parameters
Name Type Description
javaObject Object A Java object from system code such as a Packages call.
Table 2. Returns
Type Description
Object A JavaScript object if the parameter can be converted, otherwise it returns the Java object.

var tu = new TableUtils("cmdb_ci_win_server");
var classes = tu.getHierarchy();
//getHierarchy returns a Java ArrayList, which is not exactly like a JavaScript Array
//for example you cannot get length
gs.print("classes = " + classes);
gs.print("classes.length = " + classes.length);
//convert to a JavaScript Array
var jsClasses = j2js(classes);
gs.print("jsClasses = " + jsClasses);
gs.print("jsClasses.length = " + jsClasses.length);
classes = [cmdb_ci_win_server, cmdb_ci_server, cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci]
classes.length = undefined
jsClasses = cmdb_ci_win_server,cmdb_ci_server,cmdb_ci_computer,cmdb_ci_hardware,cmdb_ci
jsClasses.length = 5