cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Set Authenticated User via workflow expression

dwilliams
6-Contributor

Set Authenticated User via workflow expression


In our workflows, we are using expressions to perform actions such as checkout/check in, initiate sub processes, etc.

Can anyone tell me how to authenticate a user so that the creator/updater is not wtadmin but rather the user who initiated the original process?

Thanks in advance,
Dax Williams
Business Administrator, Windchill
Lifetime Products, Inc.
-<">mailto:->

[cid:image001.jpg@01C9DE19.481F76A0]

4 REPLIES 4

Hi Dax,

you can use this code to do anything in Windchill as any user:

try{

SessionContext previous_context = SessionContext.newContext();
SessionMgr.setPrincipal(creator.getName()); // for example... You can use any user

// Your code that needs to be executed as another user...

} catch(Exception e) {
e.printStackTrace();
} finally {
if (previous_context != null) {
SessionContext.setContext(previous_context);
}
}


Iker Mendiola

Prambanan IT Services
http://en.prambanan-it.com



http://www.prambanan-it.comIker Mendiola - Prambanan IT Services

Sorry, previous_context must be defined outside try-catch block... A copy-paste mistake...

Iker Mendiola

Prambanan IT Services
http://en.prambanan-it.com



http://www.prambanan-it.comIker Mendiola - Prambanan IT Services
scaron1
4-Participant
(To:dwilliams)

Dan, here is the piece of code I am using.



// Get current user

wt.org.WTPrincipal currentUser = currentUser = wt.session.SessionHelper.manager.getPrincipal();

try {



... you code





} finally {

wt.session.SessionHelper.manager.setPrincipal( currentUser.getName() );

}









Regards, - Merci,


Serge Caron
Senior Application Engineer, Software PLM Services - Ingénieur d'application sénior, Services informatique PLM
BRT Solutions - Montreal
8268 Boulevard Pie IX, Montréal, Québec, CANADA, H1Z 3T6
TEL. 514.727.7113 / 1.877.399.7113 (EXT.230)
CEL. 514.913.3383
FAX. 514.727.2600
SCaron@brt-solutions.com <">mailto:SCaron@brt-solutions.com>
www.brt-solutions.com
scaron1
4-Participant
(To:dwilliams)

Oups, forgot a few line,



wt.maturity.PromotionNotice pbo = (wt.maturity.PromotionNotice) primaryBusinessObject;

// Get current user

wt.org.WTPrincipal currentUser = currentUser = wt.session.SessionHelper.manager.getPrincipal();

try {

wt.session.SessionHelper.manager.setPrincipal( pbo.getCreatorName() );





... you code





} finally {

wt.session.SessionHelper.manager.setPrincipal( currentUser.getName() );

}







Regards, - Merci,


Serge Caron
Senior Application Engineer, Software PLM Services - Ingénieur d'application sénior, Services informatique PLM
BRT Solutions - Montreal
8268 Boulevard Pie IX, Montréal, Québec, CANADA, H1Z 3T6
TEL. 514.727.7113 / 1.877.399.7113 (EXT.230)
CEL. 514.913.3383
FAX. 514.727.2600
SCaron@brt-solutions.com <">mailto:SCaron@brt-solutions.com>
www.brt-solutions.com
Announcements

Top Tags