Get Project Edit History in Gateway Script

Looks like I marked this one as solved a hair too quickly…

Here is what I have so far to attempt to get the LastModification attribute:

	import json
	## get gateway context to grab project manager
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	gw = IgnitionGateway.get()
	project_manager = gw.getProjectManager()
	project_names = [name for name in project_manager.getProjectNames()]
	project_manifests = []
	projects = [project_manager.getProject(name).get() for name in project_names]	## Need to get() from the java "Optional" object
	for project in projects:
		manifest = project.getManifest()
		jsonManifest = json.loads(manifest.toJson(manifest))
		project_manifests.append(jsonManifest)
		## get all resources and loop over them to find the latest timestamp from 'LastModification' attribute
		resources = project.getAllResources()
		latest = None	## update this timestamp whenever a more recent timestamp is encountered.
		for resource in resources:
			if resource.getProjectName() == project.getName():
				return({'json': resource})	## this returns an object with projectName, resourcePath, and resourceType attributes
				return({'json': dir(resource)})	## this returns a list that does not include 'getAttribute' or 'getAttributes'..
				return({'json': resource.getAttributes()})	## this also throws attribute error
				lastModification = resource.getAttribute('LastModification')	## this throws attribute error 
	d = {'project_names': project_names, 'project_manifests': project_manifests}
	return({'json': json.dumps(d)})
	

This is in a python doPost web dev resource. Gateway is running 8.1.10. You can see that I have debug return statements in the code to inspect the resource object in that last loop. The dir(resource) almost returns the same list that I would expect of the ProjectResource object, but it is missing the getAttribute and getAttributes methods I need.

1 Like