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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Find a Windchill User Object

dthompson
2-Guest

Find a Windchill User Object


I have a need to find a Windchill User object in a robot in one of my workflows. Does anyone have an example of this ?

In the workflow I know the Users login ID name as well as their Full Name. So with that information I need some assistance (example) of java code to fine Windchill user object
(wt.org.WTPrinicpalReference or wt.org.WTPrincipal).

Thanks.
Don Thompson
6 REPLIES 6

I just did something similar, although it was to find a Promotion Notice from it's number and assign it to Workflow Variable. Below is the code. I did this on the Complete transition after a user entered a number in to a task variable. Just change the class from wt.maturity.PromotionNotice to your class and update the search criteria and you should be good.

wt.query.QuerySpec qs = new wt.query.QuerySpec(wt.maturity.PromotionNotice.class);

qs.appendWhere(new wt.query.SearchCondition(wt.maturity.PromotionNotice.class,
wt.maturity.PromotionNotice.NUMBER,
wt.query.SearchCondition.EQUAL,pnNumber),new int[]{0});

wt.fc.QueryResult qr = wt.fc.PersistenceHelper.manager.find(qs);

while (qr.hasMoreElements())
{
wt.fc.WTObject obj = (wt.fc.WTObject) qr.nextElement();

if (obj instanceof wt.maturity.PromotionNotice){
promotionNotice = (wt.maturity.PromotionNotice) obj;
}
}

Try the following:



try {



wt.util.WTProperties wtPropertiesReference;

wtPropertiesReference = wt.util.WTProperties.getLocalProperties();


String ldapServicesArray = new String[] {
wtPropertiesReference.getProperty("wt.federation.org.defaultAdapter")};

String[] ldapSubtreeScope =
{wt.org.OrganizationServicesHelper.SUBTREE_SCOPE};

wt.org.GenericDirectoryContextProvider directoryContextProvider = new
wt.org.GenericDirectoryContextProvider( ldapServicesArray, ldapSubtreeScope
);

wt.org.WTUser userVariableDefinedInWorkflow =
wt.org.OrganizationServicesHelper.manager.getUser(<usernamestringvariableinw<br/>orkflow>,directoryContextProvider);



} catch (Exception error)

{

error.printStackTrace();

}





Regards,

David DeMay






I got two different solutions (from Dave DeMay and Stephen Drzewiczewski) that both worked. Thanks.

Original question was, how to find a Windchill User Object.

Don Thompson

By the way what solution is faster?


Thanks,
Dmitry

My solution was originally helped out by Dave too... Smiley Happy
Quoting Don Thompson <->:

> I got two different solutions (from Dave DeMay and Stephen
> Drzewiczewski) that both worked. Thanks.
>
> Original question was, how to find a Windchill User Object.
>
> Don Thompson



I would not look at it so much as speed but accuracy. I should have said that doing with a queryspec runs some risk if a disconnected principal issue occurs or ldap is modified somehow.Federation is also an issue for some sites. The name column of the wtuser database table is not unique. 99% of the time both solutions will probably solve the issue - just like to point out the difference.





Regards,

David DeMay



Announcements


Top Tags