Perspective Form Submission Not Capturing Session Info

I’ve configured a form submission script to record the logged in user, if one exists, as part of the form data submission. It functions as expected in the designer, but in browser I’m not seeing any session info pass through the form built in parameters. Instead I’m using the old system.perspective.getSessionInfo() and that’s working just fine.

I’m happy with my work around, but I’m puzzled why I’m not receiving any user data.

	# sessionContext is dict-like; convert safely
	sessionDict = dict(sessionContext) if sessionContext else {}
	
	# Log keys to help diagnose auth/session structure
	logger.info("sessionDict keys: %r" % sessionDict.keys())

	# Resolve username
	userName = "No User Logged In"
	userBlock = sessionDict.get("user")

	if isinstance(userBlock, dict):
		userName = userBlock.get("userName") or userBlock.get("username") or userName
	else:
		# If userBlock is missing or not a dict, log what it is
		logger.info("userBlock type=%r value=%r" % (type(userBlock), userBlock))

	logger.info("Submitting form name=%r area=%r userName=%r sessionId=%r" % (
		name,
		formContext.get("area") if isinstance(formContext, dict) else None,
		userName,
		sessionDict.get("id")
	))

image

If I try to print just sessionContext from the built in form submission component, I receive the following (with IP redacted) ":

{"id":"a2e3cb5d-2160-4c89-97dd-2f66d028e3d2","device":{"type":"browser","identifier":"b704d262-8bae-491a-9fb6-252ef7138628","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36","settings":{"pullToRefresh":true,"preventSleep":false},"accelerometer":{"timestamp":0,"x":0,"y":0,"z":0},"timezone":{"id":"America/Los_Angeles","utcOffset":-8}},"gateway":{"address":"redacted","timezone":{"utcOffset":-5,"id":"America/New_York","name":"Eastern Standard Time"},"connected":true},"geolocation":{"enabled":false,"permissionGranted":null,"options":{"accuracy":"balanced","maximumAge":0},"data":{"latitude":null,"longitude":null,"altitude":null,"accuracy":null,"altitudeAccuracy":null,"heading":null,"speed":null,"timestamp":null}},"locale":"en-US","timeZoneId":"America/New_York","user":{},"timestamp":1771449445311}

You don't need this LLM slop much "defensive" code.

You get PyJsonObjectAdapter, but it faithfully acts as a regular dictionary. Just treat it as such. You will always get a sessionContext.

userName = sessionDict.get("user", {}).get("userName", "No User Logged In")

That’s helpful from a coding standpoint, but my question is why I’m not getting information in sessionContext… Regardless of if I have a user logged in or not, I’m not getting any sessionContext and referencing that always returns ‘No User Logged In”

You need to drill deeper into the session--the props you want are not directly in the session. Look at the session props hierarchy in the designer.

I wondered about that, that maybe I was incorrectly drilling for the user information. So I printed all sessionContext to console and that’s how I discovered that I’m not getting any information in sessionContext:

That shows you are getting a sessionContext, it just doesn't have any user information.

Are you logged in, in the client session, at the time you're submitting this form?

The sessionContext.user data is coming from the auth.user property in the Designer’s Perspective Session Props. However, that data is private and is hidden in the app/browser.