<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Scripting problem with global variables in version 2.0-M2]]></title><description><![CDATA[<p dir="auto">First, I just want to say what an excellent product NetXMS is, thanks to everyone involved in making it what it is today.</p>
<p dir="auto">Now on to the issue I am experiencing, I am having a problem with scripting in that global variables do not appear to be working correctly (or I am misunderstanding how to use them, which is possibly more likely).</p>
<p dir="auto">I am defining a global variable in the following way:-</p>
<pre><code>global GlobalStringConstant = "String Value";
</code></pre>
<p dir="auto">However when I try to reference the global variable in functions, all I get is a NULL object.</p>
<p dir="auto">To test this I created a script in the script library called "TestScript" with the following code:-</p>
<pre><code>global GlobalStringConstant = "String Value";

sub main() {
	typeofValue = typeof(GlobalStringConstant);
	println "Type:-";
	println typeofValue;

	println "Value:-";
	println GlobalStringConstant;
}
</code></pre>
<p dir="auto">Then in the server console, when I issue the command "exec TestScript", I get the following output:-</p>
<pre><code>Type:-
null
Value:-


INFO: Script finished with rc=0
</code></pre>
<p dir="auto">Where I was expecting the output:-</p>
<pre><code>Type:-
string
String Value
INFO: Script finished with rc=0
</code></pre>
<p dir="auto">I am running the current development version 2.0-M2 with the 64bit binaries running on a Windows Server 2008 R2 virtual machine which is connected to a Microsoft SQL Server 2008 R2 backend database.</p>
<p dir="auto">Any assistance anyone can offer would be very much appreciated.</p>
<p dir="auto">Thanks!</p>
<p dir="auto">Simon</p>
]]></description><link>https://forum.netxms.org/topic/3672/scripting-problem-with-global-variables-in-version-2.0-m2</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 14:55:33 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/3672.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Apr 2015 13:46:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Scripting problem with global variables in version 2.0-M2 on Sat, 04 Apr 2015 15:01:22 GMT]]></title><description><![CDATA[<p dir="auto">Ahh, yes, I see what you mean - I have modified my code based on your feedback and it is working correctly now.</p>
<p dir="auto">Thank you very much for your help!</p>
<p dir="auto">Simon</p>
]]></description><link>https://forum.netxms.org/post/16278</link><guid isPermaLink="true">https://forum.netxms.org/post/16278</guid><dc:creator><![CDATA[DrCamel]]></dc:creator><pubDate>Sat, 04 Apr 2015 15:01:22 GMT</pubDate></item><item><title><![CDATA[Reply to Scripting problem with global variables in version 2.0-M2 on Sat, 04 Apr 2015 14:42:51 GMT]]></title><description><![CDATA[<p dir="auto">In your example</p>
<pre><code>global GlobalStringConstant = "String Value";
</code></pre>
<p dir="auto">Is never executed</p>
<p dir="auto">Please read this article:<br />
<a href="https://wiki.netxms.org/wiki/UM:NetXMS_Scripting_Language_(NXSL)#Script_entry_point" rel="nofollow ugc">https://wiki.netxms.org/wiki/UM:NetXMS_Scripting_Language_(NXSL)#Script_entry_point</a></p>
<p dir="auto">You implicit main is never executed, since you have an explicit main.<br />
Therefore, the variable "GlobalStringConstant" is never initialized.</p>
]]></description><link>https://forum.netxms.org/post/16277</link><guid isPermaLink="true">https://forum.netxms.org/post/16277</guid><dc:creator><![CDATA[tomaskir]]></dc:creator><pubDate>Sat, 04 Apr 2015 14:42:51 GMT</pubDate></item></channel></rss>