# \[Feature-12077\]Project Script to Get Project Names

**URL:** <https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 24, 2020, 7:09pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548 "2020-02-24T19:09:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![StephenBarnes](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@StephenBarnes](https://forum.inductiveautomation.com/u/StephenBarnes)\
**Post date:** [February 24, 2020, 7:09pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/1 "2020-02-24T19:09:36Z")

</div>

I’m looking to replicate this script from 7.9.10 to 8.0. The script first gets the project names for all the projects on the ignition server and then writes the dataset tag to a memory tag. I am trying to do the same with 8.0 but am having trouble writing the dataset information to the memory tag as my script is not writing to my memory tag. I appreciate the help.

The script for 7.9 is:

```auto
def getProjectNames():
	from com.inductiveautomation.ignition.gateway import SRContext
	from com.inductiveautomation.ignition.common.project import ProjectVersion
	projects = SRContext.get().getProjectManager().getProjectsLite(ProjectVersion.Published)
	return system.dataset.toDataSet(['Projects'], [[project.getName()] for project in projects])

def getProjectInfo():
	from com.inductiveautomation.ignition.gateway import SRContext
	from com.inductiveautomation.ignition.common.project import ProjectVersion
	
	projects = SRContext.get().getProjectManager().getProjectsLite(ProjectVersion.Staging)

	headers = [
		'Name', 
	]

	info = [
		[
		project.getName(), 
		] 
		for project in projects
	]
	return system.dataset.toDataSet(headers, info)

```

Then on another tag I am running the script:

```auto
projects = shared.Projects.getProjectInfo()
system.tag.write("[.]Projects",projects)

```

For 8.0 I am running the following script:

```auto
def getProjectNames():
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	return system.dataset.toDataSet(['Projects'], [[name] for name in IgnitionGateway.get().getProjectManager().getProjectNames()])

def getProjectInfo():
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	
	headers = [
		'Name'	
	]
	
	info = [
		[
		IgnitionGateway.get().getProjectManager().getProjectNames(),
		]
		for project in projects
	]
	
	return system.dataset.toDataSet(headers, info)

```

Then on a seperate tag I am running:

```auto
projects = shared.Projects.getProjectInfo()
system.tag.write("[.]Projects", projects)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 24, 2020, 7:16pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/2 "2020-02-24T19:16:39Z")

</div>

Please edit your post to use a code block (so we can read it). Place three backquotes (these ```) on a line above your code, and again on a line below your code.

---

<div class="post-metadata">

**Author:** ![StephenBarnes](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@StephenBarnes](https://forum.inductiveautomation.com/u/StephenBarnes)\
**Post date:** [February 24, 2020, 7:56pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/3 "2020-02-24T19:56:19Z")

</div>

I have updated my post above.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 24, 2020, 8:09pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/4 "2020-02-24T20:09:08Z")

</div>

If you can wait a few weeks, there’s going to be a `system.project.getProjectNames()` function within the next release or two.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 3, 2020, 7:10pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/5 "2020-03-03T19:10:18Z")

</div>

system.project.getProjectNames() just got merged in and will be in 8.0.11.

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [June 9, 2022, 12:26pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/6 "2022-06-09T12:26:24Z")

</div>

@paul-griffith I see this function does work from the gateway:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/e/6e184cc9c26b10725ff9e4f2b0b6d10d82b3f998.png)

One thing I am wondering is how can we get project names for all EAM agents on the EAM controller?

What we want to do is take the IP address, resolve it to a DNS, and then build the perspective client string, and for this we need the project names, especially if they are not the same on each gateway (for us this is unfortunately the case).

What we would then do is offer our users a page they can go to to see all available sites, click a link and then be taken to their desired site.

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [June 9, 2022, 2:00pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/7 "2022-06-09T14:00:47Z")

</div>

You could setup a message handler at your EAM controller to receive project names (and collect/store them as you need) from your various EAM agent gateways. Then a scheduled script in each of those to periodically [send](https://docs.inductiveautomation.com/display/DOC81/system.util.sendMessage) the [list of project names](https://docs.inductiveautomation.com/display/DOC81/system.project.getProjectNames).

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [June 9, 2022, 4:25pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/8 "2022-06-09T16:25:35Z")

</div>

@kcollins would this be the appropriate function? I’m guessing looking at the parameters that it can reach gateways on different URLs?

[https://docs.inductiveautomation.com/display/DOC81/system.util.sendMessage](https://docs.inductiveautomation.com/display/DOC81/system.util.sendMessage)

Thanks,

Nick

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 9, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/9 "2022-06-09T16:26:29Z")

</div>

`sendMessage` (can) broadcast over the gateway area network, so you’d use the gateway name(s) of the servers you want to target.

---

<div class="post-metadata">

**Author:** ![nicholas.robinson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nicholas.robinson/32/22188_2.png) [@nicholas.robinson](https://forum.inductiveautomation.com/u/nicholas.robinson)\
**Post date:** [June 9, 2022, 5:27pm UTC](https://forum.inductiveautomation.com/t/feature-12077-project-script-to-get-project-names/32548/10 "2022-06-09T17:27:26Z")

</div>

@paul-griffith @kcollins Thanks for the advice guys, this worked without much fuss. Posting the code here in case it can help answer the same question for others:

**Code on the EAM Agent** (run in the gateway context to get the hostname)

```auto
host = system.net.getHostName()
projects = system.project.getProjectNames()
payload = {
    "host": host,
    "projects": projects
}
system.util.sendMessage(
    project="centralMonitoring",
    messageHandler="projectNames",
    payload=payload,
    scope="G",
    remoteServers=["Ignition EAM"]
)

```

**Code on the EAM Controller**

```auto
def handleMessage(payload):
    """
    This message handler will be called each time a message of this
    type is received.
    Arguments:
        payload: A dictionary that holds the objects passed to this
                 message handler. Retrieve them with a subscript, e.g.
                 myObject = payload['argumentName']
    """
    logger = system.util.getLogger("Agent Project Names")
    host = payload["host"]
    projects = payload["projects"]
    logger.info("Host: {}, Projects: {}".format(host, projects))

```
