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

We are happy to announce the new Windchill Customization board! Learn more.

how to get object's creator in DataUtility?

HO_10736653
4-Participant

how to get object's creator in DataUtility?

I am trying to get objects creator in data utility. How to get Creator of Action item in DataUtilty which extends ActionItemDataUtility.

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @HO_10736653 

In the dataUtility there is method getDataValue with three variables

HelesicPetr_0-1701342073215.png

The second variable Object var2 is your object that is part of the row

You need to retype this object to your object type where you can use object.getCreator()

example 

WTPrincipalReference principa = wtp.getCreator();

 

PetrH

 

View solution in original post

4 REPLIES 4

Hi @HO_10736653 

In the dataUtility there is method getDataValue with three variables

HelesicPetr_0-1701342073215.png

The second variable Object var2 is your object that is part of the row

You need to retype this object to your object type where you can use object.getCreator()

example 

WTPrincipalReference principa = wtp.getCreator();

 

PetrH

 

Hi @HelesicPetr , Getting below error at typeCasting to DiscreteActionItem object type:

ERROR : com.ptc.core.components.beans.DataUtilityBean testuser1 - CaughtException while processing column: itemDueDate. Enable 'com.ptc.core.components.beans.DataUtilityBean' logger for full stack trace.class com.ptc.core.meta.type.common.impl.DefaultTypeInstance cannot be cast to class wt.meeting.actionitem.DiscreteActionItem (com.ptc.core.meta.type.common.impl.DefaultTypeInstance and wt.meeting.actionitem.DiscreteActionItem are in unnamed module of loader 'app')

 

Code I am trying :

public class ActionItemDueDateDataUtility extends ActionItemDataUtility{

 

private static final String CLASSNAME = ActionItemDueDateDataUtility.class.getName();

private static final Logger logger = LogR.getLogger(CLASSNAME);

 

@Override

public Object getDataValue(String comp_id, Object datum, ModelContext modelcontext) throws WTException {

 

Object returnValue = super.getDataValue(comp_id, datum, modelcontext);

boolean isEditMode = modelcontext.getDescriptorMode().equals(ComponentMode.EDIT);

logger.debug("EDIT MODE :" + isEditMode);

 

//Get Current Action Item

DiscreteActionItem issueLog = (DiscreteActionItem) datum;

 

//Get Current User

WTUser user = (WTUser) SessionHelper.getPrincipal();

 

 

//Get Creator of action Item

WTUser issueCreator = (WTUser) issueLog.getCreator().getPrincipal();

 

if ( isEditMode && issueLog instanceof DiscreteActionItem) {

if(user!=issueCreator)

{

DateInputComponent returnValue1 = (DateInputComponent) returnValue;

returnValue1.setEditable(false);

return returnValue1;

}

}

return returnValue;

}

}

Hi @HO_10736653 

In your case the object is not DiscreteActionItem .
I advice you to use a debug stop (eclipse and others ide support it) and check what type is there and how you can work with it.

 

From the error the original type is DefaultTypeInstance so you need to cast the object to this type

 

I also advice you to use if statement with instanceof to avoid that errors.

 

PetrH

Hi @HelesicPetr , Thanks for information. I have modified my code to do type casting as below. Now its working.

 

String datumObjectIdentifier = modelcontext.getTypeInstance().getPersistenceIdentifier();

wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();

wt.fc.WTReference wtref = rf.getReference(datumObjectIdentifier);

Persistable per = wtref.getObject();

WTObject obj= (WTObject) per;

DiscreteActionItem issueLog = (DiscreteActionItem) obj;

 

Top Tags