Difference between revisions of "Script Example: Recursively Collect Values from Custom Attributes"
(Created page with "This script recursively collects values of custom attribute '''contacts''' from all node parents. Collected values concatenated into single string and separated by semicolons....") |
m (Text replacement - "^" to "{{deprecated}}") |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{deprecated}} | |||
{| style="border-spacing: 20px; border: 20px solid red;" | |||
| | |||
'''WARNING''': This page is no longer updated. Please visit '''[https://www.netxms.org/documentation/nxsl-latest/#_examples_2 NetXMS Script examples]''' for current version of the documentation. | |||
|} | |||
This script recursively collects values of custom attribute '''contacts''' from all node parents. Collected values concatenated into single string and separated by semicolons. Duplicate values added only once. | This script recursively collects values of custom attribute '''contacts''' from all node parents. Collected values concatenated into single string and separated by semicolons. Duplicate values added only once. | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
global contacts = ""; | global contacts = ""; // concatenated values will be stored here | ||
global | global presence = %{ }; // value presence indicator (hash map) | ||
// walk through each parent object for current node | |||
foreach(o : GetObjectParents($node)) | foreach(o : GetObjectParents($node)) | ||
{ | { | ||
Line 10: | Line 23: | ||
} | } | ||
// Concatenated result is in "contacts" global variable | |||
println "Contacts: " . contacts; | println "Contacts: " . contacts; | ||
/** | |||
* Recursively add contacts from object and it's parents | |||
*/ | |||
sub add_contacts(curr) | sub add_contacts(curr) | ||
{ | { | ||
c = GetCustomAttribute(curr, "contacts"); | c = GetCustomAttribute(curr, "contacts"); | ||
if ((c != null) && ( | if ((c != null) && (presence[c] == null)) | ||
{ | { | ||
if (length(contacts) > 0) | if (length(contacts) > 0) | ||
Line 21: | Line 38: | ||
else | else | ||
contacts = c; | contacts = c; | ||
presence[c] = true; | |||
} | } | ||
Latest revision as of 16:13, 13 September 2022
This Wiki is deprecated and we are are currrently migrating remaining pages into product documentation (Admin Guide, NXSL Guide) |
WARNING: This page is no longer updated. Please visit NetXMS Script examples for current version of the documentation. |
This script recursively collects values of custom attribute contacts from all node parents. Collected values concatenated into single string and separated by semicolons. Duplicate values added only once.
global contacts = ""; // concatenated values will be stored here
global presence = %{ }; // value presence indicator (hash map)
// walk through each parent object for current node
foreach(o : GetObjectParents($node))
{
add_contacts(o);
}
// Concatenated result is in "contacts" global variable
println "Contacts: " . contacts;
/**
* Recursively add contacts from object and it's parents
*/
sub add_contacts(curr)
{
c = GetCustomAttribute(curr, "contacts");
if ((c != null) && (presence[c] == null))
{
if (length(contacts) > 0)
contacts = contacts . ";" . c;
else
contacts = c;
presence[c] = true;
}
foreach(o : GetObjectParents(curr))
{
add_contacts(o);
}
}