# Accessing tag path with writeAsync callback?

**URL:** <https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 30, 2022, 9:15pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838 "2022-03-30T21:15:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 30, 2022, 9:15pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/1 "2022-03-30T21:15:10Z")

</div>

I am trying to write a custom function that will be called whenever we want to write to a tag in a Perspective project, with the intention of logging the operator action.

Is it possible to access the actual tagPath and tagValue used in the system.tag.writeAsync method, when inside the callback function?

It looks like only the quality code is returned, which seems odd to me. If the quality is BAD, how will we know WHICH write item was bad?

My function looks something like this at the moment:

```auto
	scriptName = "perspective.tag.writeAsync"
	
	def writeResponse(tagResponses):
		
		scriptName = "perspective.tag.writeResponse"
		
		for result in tagResponses:
			if result.good:
				logger.info(scriptName + " success writing '%s'" % (result))
				###perspective.log.operAction("Tag Write", target, value, session)
			else:
				#### TO DO: ###perspective.log.error()
				logger.error(scriptName + " - failed to write '%s' " % (result))
			# end if
		# end for
	# end def
	
	logger.info(scriptName + "SessionInfo: %s" % sessionInfo)
	system.tag.writeAsync(tagPaths, values, writeResponse)
	
	
# end def

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2022, 9:18pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/2 "2022-03-30T21:18:03Z")

</div>

Make sure `tagPaths` is in scope somehow, either by passing it into your function or making sure it’s defined beforehand.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2022, 9:19pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/3 "2022-03-30T21:19:38Z")

</div>

Example:

```python
def handleResponses(paths, responses):
    # do stuff here

tagPaths = [...]
values = [...]
system.tag.writeAsync(tagPaths, values, lambda x: handleResponses(tagPaths, x))

```

You know which item was bad by matching the indices up.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 30, 2022, 10:28pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/4 "2022-03-30T22:28:08Z")

</div>

Thanks Kevin that seems to be just what i need! Might need to school myself up on what that **lambda** part is doing though.

Something else that is confusing me a bit here, and with Perspective in general..  
When using [system.perspective.getSessionInfo()](https://docs.inductiveautomation.com/display/DOC80/system.perspective.getSessionInfo), i was hoping that this would return the currently active session, in relation to where the script is being called.  
For instance, if i'm clicking a button, and run this script, i would like to have the session corresponding to the page and the user that is currently pressing the button.

I see that it can return multiple sessions, and that you can filter by username and project, but is there a guaranteed way to return the exact session you're already in?  
It would make sense to be able to return based on this property for instance:

> self.session.props.id

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2022, 10:40pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/5 "2022-03-30T22:40:18Z")

</div>

Well, sure, one of the properties in the list of objects returned by `getSessionInfo` is the session id, so you just have to do that filtering yourself if you want the info on the current session.

```python
	sessionId = self.session.props.id
	
	sessionInfos = system.perspective.getSessionInfo()
	
	filtered = filter(lambda x: x.id == sessionId, sessionInfos)
	
	if len(filtered) > 0:
		print filtered[0]

```

(there’s that `lambda` again)

---

<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 30, 2022, 10:44pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/6 "2022-03-30T22:44:33Z")

</div>

If you’ve already got a Perspective component, you don’t need to call `system.perspective.getSessionInfo`, also; you can just call `self.session.getInfo()` to get the local session’s info.

[https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods#PerspectiveComponentMethods-CustomMethods](https://docs.inductiveautomation.com/display/DOC81/Perspective+Component+Methods#PerspectiveComponentMethods-CustomMethods)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 30, 2022, 10:50pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/7 "2022-03-30T22:50:22Z")

</div>

Oh, yeah, do that. Way better.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 30, 2022, 10:56pm UTC](https://forum.inductiveautomation.com/t/accessing-tag-path-with-writeasync-callback/57838/8 "2022-03-30T22:56:32Z")

</div>

Thanks guys, I believe it needs to be `self.session.getInfo()` FYI.  
The confusing part of that manual section on a session object, is that it says that `.getInfo()` returns a list of sessions, when it is actually only returning the one object related to this particular session object.

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