User-defined JavaScript

NSM client users can define their own JavaScript to use in the JavaScript parameters. Two types of user-defined JavaScript exist: JavaScript functions and custom JavaScript.

JavaScript functions

NSM client users can define their own JavaScript in the <code> tag of an inject parameter definition.

Note: For JavaScript functions, the <code> and <methodCall> tags must be populated. You must also specify any <arguments> that are used.

The <code> tag contains the full JavaScript function. This function must return a string. The <arguments> tag is populated depending on whether the user-defined JavaScript function takes arguments. The <methodCall> tag specifies the name of the function to call in the <code> tag.

The following example shows a JavaScript function that takes arguments in an inject parameter definition called IP03 in a NSM service template XML.
.
.
.
<injectParameter>
	<name>IP03</name>
	<description>Returns the sum of three numbers</description>
	<methodCall>sumOfThree</methodCall>
	<arguments>param1,param2,param3</arguments>
	<code>
	function sumOfThree(x,y,z)
	{ var k = parseInt(x) + parseInt(y) + parseInt(z); return k.toString(); }
	</code>
</injectParameter>
.
.
.
The following example shows a JavaScript function that does not take arguments in an inject parameter definition called IP04 in a NSM service template XML. Note that the <arguments> /<arguments> tag pair is not specified.
.
.
.
<injectParameter>
	<name>IP04</name>
	<description>Returns the string 10</description>
	<methodCall>theMethodName</methodCall>
	<code>
	function theMethodName() { var k = 10; return k.toString(); }
	</code>
</injectParameter>
.
.
.

Custom JavaScript

NSM client users might want to define their own custom JavaScript. The <code> tag contains a JavaScript statement.
Note: For custom JavaScript, the <code> tag must be populated. The <arguments> and <methodCall> tags are ignored.
The following example shows a custom JavaScript function in an inject parameter definition called IP06 in a NSM service template XML. Note that the <arguments> /<arguments> tag pair and the <methodCall> /<methodCall> are not specified.
.
.
.
<injectParameter>
	<name>IP06</name>
	<description>Returns the current year</description>
	<code>
		var d = new Date(); d.getFullYear().toString();
	</code>
</injectParameter>
.
.
.