Authenticate to Teamcenter in a system context (no currentUser)

0
Hi,I'm currently working on a Teamcenter integration project where I need to implement a scheduled event and task queue to fetch data from Teamcenter.As part of the process, I'm using the Login action to authenticate with Teamcenter. It works as expected when triggered by a logged-in user session. However, when the same login action is executed via a scheduled event, I encounter the following error:   Cannot invoke "com.mendix.systemwideinterfaces.core.IUser.getLanguage()" (see screenshot below) It seems this issue might be due to the Teamcenter login Java action expecting an active user session context. In the schedule event current session is empty where as in task queue its a different current session.Additionally, when using a task queue, I receive another error:   Association refers to a non-existing object, which leads to a foreign key constraint violation.   As a workaround I also tried to use use 'executeMicroflowAsUser' from Community Commons and run the microflow as a user within the Scheduled Event but I get below error. This errors seems to be Mendix security related but I created a user and give that user required user role.    I wanted to check if anyone in the community has successfully used the Teamcenter login action in a scheduled event or background task (e.g., via Task Queue or RunMicroflowInBackground Java action)? Any insights or workarounds would be greatly appreciated.   Thanks in advance!
asked
3 answers
1

I have encountered the same issue before. 

 

The main issue here is that the Java actions of the TcConnector retrieve the TcConnector.TCSession and/or TcConnector.Cookie from the database using the session of the current user. The CurrentSession that is used to retrieve the TCSession / Cookie, however, has not been committed to the database. The task queue creates a new session for the user.

 

The way to solve this is to commit $currentSession at the start of the microflow that is performed on the TaskQueue. This needs to be done in a separate transaction (using commitInSeparateDatabaseTransaction Java action from CommunityCommons).

answered
0

Hi Mohammed,

We've integrated Teamcenter with Mendix in our application as well (built on version 9.18.3). To handle background operations, we created a dedicated Teamcenter user in Mendix, which is used to run microflows via Scheduled Events.

In the Community Commons module, there's a Java action called ExecuteMicroflowAsUser. You can use this to run your required microflows under the context of the Teamcenter user, which helps avoid session-related issues. Please refer the attached Image.

Hope this helps!

 

image.png

answered
0

I did it recently but I had difficulties too. 

I upgraded this app from 10.12 to 10.18 and the behaviors changed. 

In 10.12 I had to fork the community commons action, but in 10.18, my fork stopped working and the updated community commons worked…

something makes my case special (and experimental), I have two levels of scheduled tasks. First level is parsing a large bom, which generate the second level for batch processing of the parts. I did assign 2 different mendix users for each, and maybe it helped. 

answered