<?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[Returning array from custom function in NXSL]]></title><description><![CDATA[<p dir="auto">Hi. I'm new to NetXMS and I'm loving it - it's great.<br />
I'm using ver 2.0.2, and I'm trying to write function for a common task in script library which should return array. However returned value is string with text that looks like it is reference to the array or similar. So I have in one script library called cfunctions:</p>
<pre><code>sub getToken(data) {
text=data[1];
delimiter=data[2];
position=data[3];
i=index(text,delimiter,position);
if (i==0) {
token=substr(text,position);
position=null;
} else {
token=substr(text,position,i-position);
position=i+1;
}
return %(text,delimiter,position,token);
}
</code></pre>
<p dir="auto">then in another script i have:</p>
<pre><code>use cfunctions;
t="aa,bb,cc,dd";
delimiter=",";
position=1;
array data;
data[1]=text;
data[2]=delimiter;
data[3]=position;
data[4]="";1

data=cfunctions.getToken(data);
...
</code></pre>
<p dir="auto">If I try to use data[1] after call to my function I get error that object is not a container, if I print typeof(data) I get that it is string, and if I print variable data  I get someting like: [A@0x7ff74c30c9f9].</p>
<p dir="auto">I also tried to create array in getToken function and populate it one by one (array retr; retr[1]=..., retr[2], .... return retr;) but I get same problem.</p>
<p dir="auto">So how can I return and use returned array from my function.</p>
<p dir="auto">Thank you.</p>
]]></description><link>https://forum.netxms.org/topic/4362/returning-array-from-custom-function-in-nxsl</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 15:27:18 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/4362.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 21 Mar 2016 16:11:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Returning array from custom function in NXSL on Mon, 21 Mar 2016 22:46:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/victor" aria-label="Profile: victor">@<bdi>victor</bdi></a> said in <a href="/post/19460">Returning array from custom function in NXSL</a>:</p>
<blockquote>
<p dir="auto">Hi,</p>
<p dir="auto">dot (.) is a string concatenation operation, so line</p>
<p dir="auto">data=cfunctions.getToken(data);</p>
<p dir="auto">concatenates value of variable cfunctions (likely null) with returned array, which resulted in a null converted to string concatenated with array converted to string.</p>
<p dir="auto">Best regards,<br />
Victor</p>
</blockquote>
<p dir="auto">It all makes sense now. So easy when master explains it. <img src="https://forum.netxms.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=72b86a538fc" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
<p dir="auto">Thank you.</p>
]]></description><link>https://forum.netxms.org/post/19468</link><guid isPermaLink="true">https://forum.netxms.org/post/19468</guid><dc:creator><![CDATA[mmladinov]]></dc:creator><pubDate>Mon, 21 Mar 2016 22:46:56 GMT</pubDate></item><item><title><![CDATA[Reply to Returning array from custom function in NXSL on Mon, 21 Mar 2016 17:48:12 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">dot (.) is a string concatenation operation, so line</p>
<p dir="auto">data=cfunctions.getToken(data);</p>
<p dir="auto">concatenates value of variable cfunctions (likely null) with returned array, which resulted in a null converted to string concatenated with array converted to string.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/19460</link><guid isPermaLink="true">https://forum.netxms.org/post/19460</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Mon, 21 Mar 2016 17:48:12 GMT</pubDate></item><item><title><![CDATA[Reply to Returning array from custom function in NXSL on Mon, 21 Mar 2016 17:28:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tomaskir" aria-label="Profile: tomaskir">@<bdi>tomaskir</bdi></a> said in <a href="/post/19454">Returning array from custom function in NXSL</a>:</p>
<blockquote>
<p dir="auto">Can you replicate the problem in a simple to use function?</p>
<p dir="auto">[snip]</p>
<p dir="auto">So it sounds like your problem is somewhere else.</p>
</blockquote>
<p dir="auto">Thank you for your reply. You are right. I tried your suggestion of simple function and it worked, so I tracked the problem to calling my function by library_name.function_name(), instead of just function_name().</p>
<p dir="auto">I don't know if this other syntax of calling ( lib.fn() ) should work or not. I mean, in my code, the correct function was called even with lib.fn() syntax, and it did it's job, just the returning of an array was a problem. (I tested returning just a string and that worked fine).</p>
<p dir="auto">Do you think this was just mistake in my code and it half-worked by accident, or is this a bug and I should report it somewhere? Anyway, thank you for your help.</p>
]]></description><link>https://forum.netxms.org/post/19457</link><guid isPermaLink="true">https://forum.netxms.org/post/19457</guid><dc:creator><![CDATA[mmladinov]]></dc:creator><pubDate>Mon, 21 Mar 2016 17:28:45 GMT</pubDate></item><item><title><![CDATA[Reply to Returning array from custom function in NXSL on Mon, 21 Mar 2016 16:27:26 GMT]]></title><description><![CDATA[<p dir="auto">Can you replicate the problem in a simple to use function?</p>
<p dir="auto">Using this in "Execute server script" works fine for example:</p>
<pre><code>sub test() {
  return %(1,2,3);
}

return test()[1];
</code></pre>
<p dir="auto">Moving the function "test()" to a library script named "test_func" and then running this script also works fine:</p>
<pre><code>use test_func;

return test()[1];
</code></pre>
<p dir="auto">So it sounds like your problem is somewhere else.</p>
]]></description><link>https://forum.netxms.org/post/19454</link><guid isPermaLink="true">https://forum.netxms.org/post/19454</guid><dc:creator><![CDATA[tomaskir]]></dc:creator><pubDate>Mon, 21 Mar 2016 16:27:26 GMT</pubDate></item></channel></rss>