Skip to main content
5-Regular Member
November 30, 2023
Solved

how to get object's creator in DataUtility?

  • November 30, 2023
  • 1 reply
  • 1955 views

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

 

Best answer by HelesicPetr

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

 

1 reply

HelesicPetr
22-Sapphire II
22-Sapphire II
November 30, 2023

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

 

PetrH
5-Regular Member
November 30, 2023

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;

}

}

HelesicPetr
22-Sapphire II
22-Sapphire II
November 30, 2023

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

PetrH