It's all about the answers!

Ask a question

getting the previous value of the attribute using javascript in RTC


Vivek Pandey (4321738) | asked Mar 16 '17, 3:59 a.m.

 I'm trying to write a validation customization in RTC, which would compare the previous value and new value of the attribute.


The validation would fail if either previous or new value contains certain 'sub-string'.

Guess, all the attribute customization functions return only new / current value of the attribute.

I have tried using the additional attribute with calculated value customization to store previous value, but it still does not work as expected in some of the cases for validation to be successful.

Accepted answer


permanent link
Ralph Schoon (63.4k33646) | answered Mar 16 '17, 4:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Mar 16 '17, 4:08 a.m.

It is not possible to access the previous value of an attribute in JavaScript attribute configuration. What you are trying should be implemented as a work item save advisor. See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/ as an example for an advisor. In the Java API you can access the old and the new state.


 
"I have tried using the additional attribute with calculated value customization to store previous value, but it still does not work as expected in some of the cases for validation to be successful."

This is an ugly hack and the statement does not provide enough information to help, in case you expected help. 

Vivek Pandey selected this answer as the correct answer

Comments
Vivek Pandey commented Mar 16 '17, 7:40 a.m. | edited Mar 16 '17, 8:28 a.m.

 Thank you Ralph !

the hack is something like this :

1. For Attribute A, I have created attribute B, 
2. so whenever, Value of A does not contain string "Freeze" , value of A gets copied to Attribute B.
3. When Value of A contains string ' freeze' , value of attribute B is not changed ( giving me previous value).
4. So, Validation fails if , either Attribute A or B value contains string 'Freeze' , Validation on save of workitem fails.
5. so, this way, I'm restricting addition or removal from freeze status of the attribute.

Above works but big problem with this solution is, even if some other attribute C is changed or status is changed, validation rule is run and it throws error.

So, I was looking for validation only when attribute A changes  ( I know that may not be possible), so, was interested to check, if there is any other way to capture the previous value of the attribute A and fail validation based on it.



Ralph Schoon commented Mar 16 '17, 8:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I don't know if you can get it working with the hack you use. I would discourage trying. See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/ as an example for an advisor. In the Java API you can access the old and the new state. The download from https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ should have the code.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.