Access to Session Attributes from Workflow

Daniel G, modified 5 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Hi.
I want to access to the attributes that are stored in session when a workflow task is executed. I've tried many things but I'm not able to do it.
HttpServletRequest httpServletRequest = serviceContext.getRequest();         HttpSession httpSession = httpServletRequest.getSession();
&nbsp;&nbsp; &nbsp; List<long>gruposCarencia= ( List<long>)httpSession.getAttribute("LIFERAY_SHARED_GruposCarencia");
</long></long>
This is always null because serviceContext.getRequest() is null.
Could anyone help me? Thanks in advance!
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Hi, Are you looking for some  particular  data from session object  while executing workflow task ? You can rather store that data/object in servicecontext while initiating the workflow and use it while executing task.
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
Daniel G:
I want to access to the attributes that are stored in session when a workflow task is executed. I've tried many things but I'm not able to do it.
A workflow might run outside of any request, thus there's no request available. What kind of data are you looking for, to solve which problem?
Daniel G, modified 5 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Thanks both of you.I have a custom parameter which store a list of ids. This list is modified in a portlet and should be modified with this workflow too. So I can't pass it when the workflow starts because it could be modified by the portlet. Morevoer, I need to store again the value in session when executing the workflow, so I need to access to this parameter during the task, for getting the value and for storing it again.
Any ideas?

​​​​​​​Thanks again!
thumbnail
Mohammed Yasin, modified 5 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts
Simplest  way  is you  persist this information in Database  and then  retrieve , update etc  
Daniel G, modified 5 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Thanks, but this option is not possible for me because I have to compare this attribute in navigations so has to be stored in session.

I've tried  also this: PortalSessionThreadLocal.getHttpSession();
but it does not work neither.

Regards
thumbnail
Olaf Kock, modified 5 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
That's because workflow scripts are not tied to a HttpRequest - they can be triggered by API calls, e.g. timer based, when there's simply no person signed in to the portal at all.
We might be able to help you if you let us know the problem you're trying to solve. And no, "comparing session attributes with something" doesn't count as a problem. Use Business Terms: What are the requirements, what is the story, that you're trying to implement?
Daniel G, modified 5 Years ago. Regular Member Posts: 141 Join Date: 3/14/17 Recent Posts
Thanks for the answer.
I've had a list of sites that are shown in every navigation if an expando value matches a fixed value.This list is updated in a portlet which changes the value of this site expando, and it should be updated too with the portlet. A job inserts in database all the sites which have this expando value and the user which has a certain role in the site, and when the user is logged in, it is stored in session the list with the sites only for that user. 
This is why I want to do it with a parameter session, because I can't imagine another way to do it. Database access in every navigation is not possible because it makes the portal too slow. The solution that I'm trying to implement is valid in terms of  performance.
Regards.