Get type of field ($L.source) with JavaScript in Link file?

Hello HPSM Community,

we tried to identify $L.source fields types to fill some of them dynamically and tried following line:

typeof(system.vars.$L_source[fieldname])

for example in case of ci
typeof(system.vars.$L_source[sm.device.display.name])

we want to see if its a string, boolean, array or structure... unfortunately this line always gives back "object". Any other way/idea to get correct type?

Thx and br

Vesp

  • try this

    system.functions.type(system.vars.$L_source[sm.device.display.name]);
  • I'm unclear on what you're trying to do.  What's the $L.source variable?  What's your javascript look like?

    If you're trying to determine the data type of a particular element, you can do that with the 'system.functions.type', or there is the javascript native function typeof...

    Let's pretend you're trying to generate a javascript that will take a value from a record as a parameter and return for you the data type of that value.  (You wouldn't need javascript to do this, but let's pretend you wanted to use javascript for some reason).

    function getType(field){
    	var sourceType = system.functions.type(field);
    	if (sourceType == 1)
    		return "number";
    	if (sourceType == 2)
    		return "character";
    	if (sourceType == 3)
    		return "date/time";
    	if (sourceType == 4)
    		return "logical";
    	if (sourceType == 5)
    		return "label";
    	if (sourceType == 6)
    		return "file/record";
    	if (sourceType == 7)
    		return "offset";
    	if (sourceType == 8)
    		return "array";
    	if (sourceType == 9)
    		return "structure";
    	if (sourceType == 10)
    		return "operator";
    	if (sourceType == 11)
    		return "expression";
    }

    basically, this script takes the OOB function 'type' which returns the Service Manager data types as a numeric value, and converts it into plaintext.