<?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[How to find source name in pointlink]]></title><description><![CDATA[<p dir="auto">Newbie here:</p>
<p dir="auto">I am trying to setup a pointlink between datapoints of two different datasources. The source point is a numeric value, which must return a string value. I need the source datapoint name to appear in the string as well - I.e. if my source datapoint name is point1, the return string will be point1_1 -<br />
but I want to implement programmatically something like this:</p>
<pre><code>var x = source.value;
if(x == 1.0)
    return [sourcename]+'_1';
else
    return [sourcename]+'_0';
</code></pre>
<p dir="auto">Is there a way to achieve this? Our production setup will have around 400 of these pointlinks so it's really not practical to let the client manually input the  datapoint name for each of these strings.</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.mango-os.com/topic/2772/how-to-find-source-name-in-pointlink</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Nov 2026 08:46:27 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/2772.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 20 May 2017 18:28:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to find source name in pointlink on Tue, 23 May 2017 14:44:48 GMT]]></title><description><![CDATA[<p dir="auto">Certainly! Welcome to our forum!</p>
]]></description><link>https://forum.mango-os.com/post/14507</link><guid isPermaLink="true">https://forum.mango-os.com/post/14507</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Tue, 23 May 2017 14:44:48 GMT</pubDate></item><item><title><![CDATA[Reply to How to find source name in pointlink on Tue, 23 May 2017 08:17:58 GMT]]></title><description><![CDATA[<p dir="auto">Hi phildunlap</p>
<p dir="auto">Thank you for your reply - it would be great if this information could be readily available from within the source/target objects but this solution should do the trick - I'll try it out.</p>
]]></description><link>https://forum.mango-os.com/post/14504</link><guid isPermaLink="true">https://forum.mango-os.com/post/14504</guid><dc:creator><![CDATA[mariealtin]]></dc:creator><pubDate>Tue, 23 May 2017 08:17:58 GMT</pubDate></item><item><title><![CDATA[Reply to How to find source name in pointlink on Mon, 22 May 2017 19:25:47 GMT]]></title><description><![CDATA[<p dir="auto">Hi mariealtin,</p>
<p dir="auto">Unfortunately there is not a way to currently reference information about the target or source points from within the script. It wouldn't be very much to add, so I'll bring it up to people.</p>
<p dir="auto">One could programmatically fill those in, if you're interested in a workaround. Simply keep using "[sourcename]" where you'd like the name in the script, perhaps like this,</p>
<pre><code>var x = source.value;
if(x == 1.0)
    return '[sourcename]_1';
else
    return '[sourcename]_0';
</code></pre>
<p dir="auto">Then export your pointLinks and dataPoints to JSON, and try out this python script:</p>
<pre><code>import json

configFile = open("/path/to/config.json")
config = json.load( configFile )
configFile.close()

dpXidMap = {}
for dp in config["dataPoints"] :
    dpXidMap[dp["xid"]] = dp

for pl in config["pointLinks"] :
    pl["script"] = pl["script"].replace("[sourcename]", dpXidMap[pl["sourcePointId"]]["name"])

outputFile = open("/path/to/output.json", "w+")
outputFile.write(json.dumps(config, separators=(",",": "), indent=4, sort_keys=False))
outputFile.close()
</code></pre>
<p dir="auto">Which should do all that text replacement for you, and write JSON you can import to the output.json file.</p>
]]></description><link>https://forum.mango-os.com/post/14486</link><guid isPermaLink="true">https://forum.mango-os.com/post/14486</guid><dc:creator><![CDATA[phildunlap]]></dc:creator><pubDate>Mon, 22 May 2017 19:25:47 GMT</pubDate></item></channel></rss>