Add an additional column in View History Dialog to see the time elapsed for each status.
This is a modified version of the solution written by Bruno for the same topic.
We will accomplish this task with an attribute in the status table and an object-level launch point script written in Jython.
1. Add a column in PRSTATUS table, Name: ELAPSEDTIME, Type: Duration.
2. Display this column into View History Dialog using the application designer of the PR application.
2. Write an Object Launch Point Script: Object: PRSTATUS , Save, Add, AfterSave. Copy below the body and paste it.
if interactive:vStatusSet = mbo.getMboSet("$vStatusSet","PRSTATUS","PRNUM = :PRNUM and siteid = :siteid")vStatusSet.setOrderBy("changedate desc")vCurStatus = vStatusSet.getMbo(0)vPreviousStatus = vStatusSet.getMbo(1)vMinutes = 60000if vStatusSet.count()>1:diff = (vCurStatus.getDate("changedate").getTime() - vPreviousStatus.getDate("changedate").getTime() )/vMinutes # in minutes#divisionmodulo function of python 2 outputs; first is quotient, 2nd is remaindervDiff = divmod(diff,60)vCurStatus.setValue('ELAPSEDTIME', str(vDiff[0]) + ':' + str(vDiff[1]), 2L)else:vCurStatus.setValue('ELAPSEDTIME', str('00') + ':' + str('00'), 2L)
- -----------------------------------
- interactive: is an implicit variable; human interaction
- setOrderBy: is orderby clause of SQL
- getTime() : to convert the date into decimal
- divmod(): a python's math function DivisionModulo. the output is like (3,5) first is quotient, 2nd is remainder
- vDiff[0]: get first value from the variable
This comment has been removed by a blog administrator.
ReplyDelete