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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Calculate an attribute onchange of another attribute

Sha11
12-Amethyst

Calculate an attribute onchange of another attribute

Hello,

 

I have a requirement where I have to populate an attribute if a specific value was selected for one of the other attributes. The user will not view the object after editing, so I cannot make of data utility and layout.

 

I know that we can use a data utility to record the onchange() event using comboBox and invoke a jsp file. But I am not sure what exactly to be done after invoking a method in jsp file since I want to invoke a java method which will do a set of validation and manipulation to calculate the attribute value.

 

Requesting all to shed some light on the possible solution.

 

Thanks,

Hari

1 ACCEPTED SOLUTION

Accepted Solutions

If you would like to do it with calculated attributes, you can implement your own logic. Create a class and implement it with 

implements BusinessAlgorithm

see the development guide for an example https://support.ptc.com/help/wnc/r12.1.1.0/en/#page/Windchill_Help_Center/customization/WCCG_BusLogicCust_TypeManager_CalculatedAttribute.html

 

If you rather would like to store it as a value in the database, then you need to create a Pre Checkin trigger to set the attribute based on the other attribute values. 

 

 

 

View solution in original post

7 REPLIES 7
joe_morton
17-Peridot
(To:Sha11)

Have you looked into using calculated attributes? Might be a simpler approach.

 

Reference: https://www.ptc.com/en/support/article/cs41117

 

Sha11
12-Amethyst
(To:joe_morton)

Hello @joe_morton ,

 

There are many validations that I need to perform and also establish DB connection for the calculation of the attribute, hence I do not think this requirement can be achieved through Calculated attribute functionality. Is it possible to invoke a custom java method through calculated attribute formula?

If you would like to do it with calculated attributes, you can implement your own logic. Create a class and implement it with 

implements BusinessAlgorithm

see the development guide for an example https://support.ptc.com/help/wnc/r12.1.1.0/en/#page/Windchill_Help_Center/customization/WCCG_BusLogicCust_TypeManager_CalculatedAttribute.html

 

If you rather would like to store it as a value in the database, then you need to create a Pre Checkin trigger to set the attribute based on the other attribute values. 

 

 

 

Sha11
12-Amethyst
(To:BjoernRueegg)

Hello @BjoernRueegg ,

 

Thank you for your suggestion, I have implemented the calculated attribute functionality and its almost working as expected. I am facing one issue in a use case, I want this new attribute to be calculated when its null or blank, if the calculated attribute has a value, new value is not needed to be calculated.

 

I wrote this value check logic using persistable adapter as shown below.

 

PersistableAdapter obj = new PersistableAdapter(data, null, SessionHelper.getLocale(), new UpdateOperationIdentifier());

obj.load("calculatedAttribute");

String testNumber = (String) obj.get("calculatedAttribute");

if(testNumber==null || StringUtils.isBlank(testNumber)) {

     //method to calculate the attribute value

}

 

Somehow an exception is being thrown in the obj.load() line, do you have any suggestion as to how we can easily determine if the value is null or not before or after invoking the execute method of business algorithm.

 

PFA log file with exception stack trace.

 

 

rhart
14-Alexandrite
(To:Sha11)

You can call the obj.load inside a try{} and then handle the exceptions in a catch{}, that’s the way I’ve been doing it so I hope it’s right 

Sha11
12-Amethyst
(To:rhart)

I have done it in the same way, but where I am confused is why the obj.load() line is giving an exception. The attribute that I am trying to load is associated with the object but still some exception is getting triggered.

Why are you loading the Persistable Adapter with the UpdateOperationIdentifier? Please change that one to:

PersistableAdapter obj = new PersistableAdapter(object, null, SessionHelper.getLocale(), new DisplayOperationIdentifier());

Could it be, that this attribute is not on the edit layout?

 

Top Tags