<?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[nxShell: setPrimaryName doesn't work [Solved]]]></title><description><![CDATA[<p dir="auto">Hi to all!</p>
<p dir="auto">I'm trying to create a script for nxShell which will allow me to set the primary name of some hosts in my network. Both primary name to set and hostnames to be modified are stored in two files. I created this script:</p>
<pre><code># coding: utf-8

class SetPrimaryName:
	def out(self):
		i=0
		PrimaryNames = open("/PATH/TO/FILE/PRIMARYNAME").readlines()
		for nome in open("/PATH/TO/FILE/HOSTNAMESTOMODIFY").readlines():
			nodo = session.findObjectByName(nome.strip())
			primaryName = PrimaryNames[i]
			if nodo:
				nodeID =nodo.getObjectId()
				print "To node %s with id %d I want to set Primary Name %s"%(nome.strip(), nodeID, primaryName)
				modificatore = NXCObjectModificationData(nodeID)
				print
				modificatore.setPrimaryName(primaryName)
				i+=1
spn = SetPrimaryName()
spn.out()
</code></pre>
<p dir="auto">Everything works fine but nothing happens in NetXMS and the primary name of the selected hosts stays the same. Am I doing something wrong? My doubt is focused on "modificatore", because it's the second time I try to modify data already stored in NetXMS (does anyone remember my still unresolved problem posted <a href="/topic/2405">here</a>? ) but I'm unable to accomplish this goal.<br />
Thanks in advance for the support!</p>
]]></description><link>https://forum.netxms.org/topic/2438/nxshell-setprimaryname-doesn-t-work-solved</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 13:29:50 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/2438.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Jun 2013 10:05:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to nxShell: setPrimaryName doesn't work [Solved] on Fri, 14 Jun 2013 08:56:23 GMT]]></title><description><![CDATA[<p dir="auto">Thank you Victor! With one answer you solved two problems! Just in case anyone has the same problem I'll post the working code as example of both script:</p>
<pre><code># coding: utf-8

class SetPrimaryName:
	def out(self):
		i=0
		PrimaryNames = open("PATH/TO/FILE/PRIMARYNAME.TXT").readlines()
		for nome in open("/PATH/TO/FILE/HOSTNAMESTOMODIFY.TXT").readlines():
			nodo = session.findObjectByName(nome.strip())
			primaryName = PrimaryNames[i]
			if nodo:
				nodeID =nodo.getObjectId()
				print "To node %s with id %d I want to set Primary Name %s"%(nome.strip(), nodeID, primaryName)
				modificatore = NXCObjectModificationData(nodeID)
				modificatore.setPrimaryName(primaryName)
				session.modifyObject(modificatore)
				i+=1
spn = SetPrimaryName()
spn.out()
</code></pre>
<p dir="auto">If you want to set custom attributes in already existing nodes, or if you want another example, you can find the script <a href="/topic/2405">here</a>.</p>
]]></description><link>https://forum.netxms.org/post/10542</link><guid isPermaLink="true">https://forum.netxms.org/post/10542</guid><dc:creator><![CDATA[BlackMamba]]></dc:creator><pubDate>Fri, 14 Jun 2013 08:56:23 GMT</pubDate></item><item><title><![CDATA[Reply to nxShell: setPrimaryName doesn't work [Solved] on Thu, 13 Jun 2013 13:01:54 GMT]]></title><description><![CDATA[<p dir="auto">Hi!</p>
<p dir="auto">It seems that you don't do real modification. Creating NXCObjectModificationData is not enough - after populating it you should call session.modifyObject with your NXCObjectModificationData object as argument. Should be something like</p>
<p dir="auto">session.modifyObject(modificatore)</p>
<p dir="auto">in your case.</p>
<p dir="auto">Best regards,<br />
Victor</p>
]]></description><link>https://forum.netxms.org/post/10536</link><guid isPermaLink="true">https://forum.netxms.org/post/10536</guid><dc:creator><![CDATA[victor]]></dc:creator><pubDate>Thu, 13 Jun 2013 13:01:54 GMT</pubDate></item></channel></rss>