It's all about the answers!

Ask a question

Setting date attribute based on Work item status


Nitin Kaushik (11118) | asked Oct 03 '17, 9:15 a.m.

 Hi 

i have a requirement to set date attribute to current date as soon as the work item reaches a certain state - lets say "Ready for QA". I am able to perform up till this level but the limitation is the value of date attribute will keep on changing as soon as there is modification in some other attributes of work item. How can i restrict the Java script to only run once when the state is being achieved not afterwards.
I have seen conditions getWorkflowAction() but i have not seen a single working example. Can I return a workflow action from a condition and store in a temporary attribute and use it my main java script ?
Can I call the condition from Calculated Values  ?

2 answers



permanent link
Donald Nong (14.5k414) | answered Oct 03 '17, 9:24 p.m.

The function getWorkflowAction() definitely works, within a Condition script. According to the document,
Conditions are a special type of customization that is used to dynamically determine required attributes. You cannot explicitly call a Condition script within a Calculated Value script.

You requirement states that the Date field is modified based on the "change" of the state ("reaches" in your description), not really the "value" of the state. You can try to use the State field only to trigger the Calculated Value script. Depending on your actual requirement, you may have to implement some complicated logic to determine whether and when to modify the Date field. Writing a Java-based advisor will be a better alternative if you are not limited to JavaScript only.


permanent link
Ralph Schoon (63.1k33646) | answered Oct 04 '17, 4:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can definitely NOT access getWorkflowAction() from a calculated value in JavaScript

For all I know it is hard to detect state changes in calculated attributes. I don't think it is better if you use Java instead of JavaScript, but I did not try hard. I know some users have used hidden attributes to store state values in order to be able to detect that a state change has happened. I find that pretty ugly. 


The best option I think would be to use a follow up action that checks on work item save if the attribute has to be changed and does it.



Comments
Nitin Kaushik commented Oct 04 '17, 7:49 a.m.

 Reasonable enough not to have some hidden attributes which can be cumbersome in a way. I will try to see a work around with follow up action.

Can someone also help me with any working example of getWorkflowAction()  in condition ?


Ralph Schoon commented Oct 04 '17, 7:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 The Java code is used in 


and


You get it from the provider configuration:

String actionId = configuration.getProviderContext()
            .getWorkflowAction();
    
So if it is not provided in the first place in a calculated value, there is likely no way to get at the data. 

In a follow up action you have better ways to detect a state change. See the examples here https://rsjazz.wordpress.com/?s=participant   

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.