Can I use the 'Session' component and set my own d...
# suitecommerce
a
Can I use the 'Session' component and set my own data to it using Session.set('myData', myData)? i will be using this data in 2 of my extensions in multiple places.
I tried this, but after I added my data to Session, the Extensibility API call - container.getComponent('Environment').getSession() started throwing an error. So I assume we're not supposed to add any data to the Session? Anyway, can I use the ProfileModel singleton instead and set some additional data to it in an extension? (something like ProfileModel.getInstance().set('myData', myData))
s
🤔
Well, it's a model so technically you can use get and set on it. It just seems risky because it would be better to go to where the model's data/structure is derived and do it there.
Without knowing the details, it kinda looks like you're trying to find a way to avoid using a global variable and so I just wonder if using this object is a better place for it.
a
Yes, you're right. Based on your response to one of my colleagues earlier on this channel, we're trying to avoid using the global SC object
s
OK, well, I'm not saying never use
SC
, I'm just saying that there's usually a better way of doing things than to use it. If you feel like you need to, then go for it, but exercise caution.
A conversation with someone else has reminded me that you could also consider using the web storage API, to store data in the browser's session
a
Thank you @Steve Goldberg for your suggestions