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

Javscript code to get logged in user

SOLVED
Highlighted
Garnet

Javscript code to get logged in user

Hi all,

is there a way to get the currently logged in user from javascript? I want to validate the promotion approvers table, so that the user didn't select himself. I added a new afterJS method to the workflowParticipantsStep where I can get the table with the principals but I have to get the the logged in user somehow.

Thx,

Tamás

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Javscript code to get logged in user

Hi Tamas,

One of the other ways is to do this from Java code using custom delegate, the OOTB delegate is marked supported for customization.

Change the highlighted  in Windchill\codebase\config\actions\PromotionRequest-actions.xml  (I will prefer to do this in custom*Action file, refer guide for more details.)

<action name="workflowParticipantsStep" required="false" preloadWizardPage="false">

        <description>Promote wizard promotion objects step</description>

        <command class="ext.CustomPromotionParticipantsFormDelegate" windowType="wizard_step"/>

      </action>

e.g.

public class CustomPromotionParticipantsFormDelegate  extends PromotionParticipantsFormDelegate  {

  @Override

  public FormResult preProcess(NmCommandBean commandBean, List<ObjectBean> objectBeans)

  throws WTException {

  // TODO Auto-generated method stub

  //getParticipantsToProcess(arg0)

  for (ObjectBean objectBean : objectBeans) {

  Object object = objectBean.getObject();

  if (object instanceof LifeCycleManaged) {

  HashMap mapp= (HashMap) getParticipantsToProcess(objectBean);

  Iterator it = mapp.entrySet().iterator();

  while (it.hasNext()) {

  Map.Entry pair = (Map.Entry)it.next();

  Iterator iter = ((Set)pair.getValue()).iterator();

  while (iter.hasNext()) {

  WTUser principal=(WTUser) iter.next();

  WTUser Sessionuser= (WTUser) SessionHelper.manager.getPrincipal();

  //System.out.println(principal+"--"+Sessionuser);

  /*

  * Note pair.getKey() will give you the role, you can execute the following only for a particular role

  *

  */

  if (principal.getName().equalsIgnoreCase(Sessionuser.getName())) {

  FormResult result;

  FeedbackMessage errors= new FeedbackMessage();

  errors.addMessage("You cannot select yourself as  "+ pair.getKey()+ " Please select any other user");

  result = new FormResult(FormProcessingStatus.FAILURE);

  result.addFeedbackMessage(errors);

  return result;

  }

  }

  }

  }

  }

  return super.preProcess(commandBean, objectBeans);

  }

}

Regards,

Bhushan

View solution in original post

3 REPLIES 3

Re: Javscript code to get logged in user

I think +you can use getRemoteUser() and getUserPrincipal() methods of HttpServletRequest object or else

wt.org.WTUser loggedInUser = (wt.org.WTUser)wt.session.SessionHelper.manager.getPrincipal();

Regards

Binesh Kumar

Medtronic MITG

Re: Javscript code to get logged in user

Hi Tamas,

One of the other ways is to do this from Java code using custom delegate, the OOTB delegate is marked supported for customization.

Change the highlighted  in Windchill\codebase\config\actions\PromotionRequest-actions.xml  (I will prefer to do this in custom*Action file, refer guide for more details.)

<action name="workflowParticipantsStep" required="false" preloadWizardPage="false">

        <description>Promote wizard promotion objects step</description>

        <command class="ext.CustomPromotionParticipantsFormDelegate" windowType="wizard_step"/>

      </action>

e.g.

public class CustomPromotionParticipantsFormDelegate  extends PromotionParticipantsFormDelegate  {

  @Override

  public FormResult preProcess(NmCommandBean commandBean, List<ObjectBean> objectBeans)

  throws WTException {

  // TODO Auto-generated method stub

  //getParticipantsToProcess(arg0)

  for (ObjectBean objectBean : objectBeans) {

  Object object = objectBean.getObject();

  if (object instanceof LifeCycleManaged) {

  HashMap mapp= (HashMap) getParticipantsToProcess(objectBean);

  Iterator it = mapp.entrySet().iterator();

  while (it.hasNext()) {

  Map.Entry pair = (Map.Entry)it.next();

  Iterator iter = ((Set)pair.getValue()).iterator();

  while (iter.hasNext()) {

  WTUser principal=(WTUser) iter.next();

  WTUser Sessionuser= (WTUser) SessionHelper.manager.getPrincipal();

  //System.out.println(principal+"--"+Sessionuser);

  /*

  * Note pair.getKey() will give you the role, you can execute the following only for a particular role

  *

  */

  if (principal.getName().equalsIgnoreCase(Sessionuser.getName())) {

  FormResult result;

  FeedbackMessage errors= new FeedbackMessage();

  errors.addMessage("You cannot select yourself as  "+ pair.getKey()+ " Please select any other user");

  result = new FormResult(FormProcessingStatus.FAILURE);

  result.addFeedbackMessage(errors);

  return result;

  }

  }

  }

  }

  }

  return super.preProcess(commandBean, objectBeans);

  }

}

Regards,

Bhushan

View solution in original post

Re: Javscript code to get logged in user

Well....
A one line solution...

PTC.navigation.GLOBAL_USER

 

 

Announcements
LiveWorx Call For Papers Happening Now!