why my calculated value script run even when the change is not triggered?
Hi, Someone who may concern,
We found a very strange issue lately.
We have 2 projects, running the same calculate value script. The purpose is that when status is changed to close, then the date will be recorded
I have configured the Dependencies as "Status" for both projects, i.e. only when user change status to close, this script will run.
dojo.provide("client.valueProvider.currentCloseDate");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("client.valueProvider.currentCloseDate", null, {
getValue: function(attribute, workItem, configuration) {
var now = dojo.date.stamp.toISOString(new Date(), {milliseconds:true, zulu:true});
var state = workItem.getValue(WorkItemAttributes.STATE);
var myOldValue = workItem.getValue(attribute);
if (state ===='xxx.state.close') {
return now;
}
else
return myOldValue;
}
});
}) ();
However, on the old project, it can work properly.
But the new project, which is created with the same script, it cannot work properly:
as long as I refresh the page for a work item with status as "Close", the close date will be updated to current time. It seems my script run without trigger of status change.
However, I also noticed for the same project, defect can not work, but task can work. both of them share the same attribute for the close date.
Then I added break point in my script, and refresh the page, the break point can not be reached.
And I tried to add a console.log in the script to make sure whether the script run, but console did not show anything.
It seems this script run before tracing ability is enabled.
Because as long as I remove the script, the correct close date can be shown properly. So I am 100% sure there are something wrong for running this script.
I am wondering any configuration may cause such issue?
Thanks!
Best Regards,
Jane Zhou
|
3 answers
You just made things very confusing.
Comments
Hi Donald,
We have the same workflow for defect and task.
And I have compared the process configuration source xml file for the previous project and current project. They are totally the same for all lines related to this attribute except the link to java script because they are in different project.
I know when calculated value will be executed, because I have used it lot in our project.
Please see the part related to close date in xml file as follows:
<customAttributes category="com.ibm.team.workitem.workItemType">
...
<customAttribute id="com.xxx.closedate" name="Close Date" type="timestamp"/>
...
</customAttributes>
<customAttributes category="com.ibm.team.workitem.workItemType.task">
...
<customAttribute id="com.xxx.closedate" name="Close Date" type="timestamp"/>
...
</customAttributes>
...
<attributeDefinition id="com.xxx.closedate" name="Close Date" type="timestamp">
<dependsOn id="com.ibm.team.workitem.attribute.state"/>
<valueProvider providerId="com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._QwfAAJ9FEeaD-oSyteFouw"/>
</attributeDefinition>
<section id="com.xxx.closedate">
<presentation attributeId="com.xxx.closedate" kind="com.ibm.team.workitem.kind.timestamp">
<property key="hideIfEmpty" value="true"/>
<property key="hideIfCreation" value="true"/>
<property key="readonly" value="true"/>
</presentation>
</section>
<tab id="com.ibm.team.workitem.tab.task.overview" layout="builtInOverviewLayout">
...
<section sectionId="com.xxx.closedate" slot="quickInfo" title="Close Date"/>
...
</tab>
<tab id="com.ibm.team.workitem.tab.overview" layout="builtInOverviewLayout">
...
<section sectionId="com.xxx.closedate" slot="quickInfo" title="Close Date"/>
...
</tab>
Best Regards,
Jane Zhou
jane zhou
commented Jun 28 '17, 10:47 a.m.
Hi Donald,
Please see my comments as follows.
Thanks!
Best Regards,
Jane Zhou
Hi Donald,
When I refresh the page for an existing work item , it did not meet all 3 conditions for the calculated value. But why it is executed? This is very confusing.
Script-based calculated valuesNote: You can find general information about script-based attribute customization in the Using scripts for attribute customization section.If you configure a Script-based calculated value, the script will be executed in three cases:
Best Regards,
Jane Zhou
Donald Nong
commented Jun 29 '17, 4:59 a.m.
I'm still not sure what's going on, but here are the things you can consider.
|
Hi Ralph,
Thanks for your reply!
The part you did not see is configured in Eclipse client to add Dependencies to the attribute close_date with calculated value. The purpose is that only when dependent attribute change then related calculated value script will run.
For my case, the calculated value is attached to attribute close_date, and dependent attribute is Status.
The same attribute close_date is shared between type of Defect and Task. However, it can work for task, but can not work for defect.
So, if my script can not work, they should not work for both cases. why it can work for task, but not for defect?
And in fact, I noticed the history did not show the close_date is updated to current time when I refresh the work item page. i.e. it only displays that way, but in database, it still record the original close_date which triggered by state change.
Thanks!
Best Regards,
Jane Zhou
|
Ralph Schoon (63.1k●3●36●46)
| answered Jun 27 '17, 6:08 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER I think the problem here is your assumption that you can detect a state change in a JavaScript attribute customization (calculated value?) for all I know you can't. The only ways to be able to do so would be the ability to access the old state which you don't have, access to the action which you don't have except in conditions or storing the old state in a hidden attribute, which I don't see.
I have summarized my experience and common misconceptions here: https://rsjazz.wordpress.com/2016/07/15/rtc-process-customization-what-you-can-and-cannot-do/
Comments
jane zhou
commented Jun 27 '17, 9:47 p.m.
Hi Ralph,
Thanks for your reply!
Please see my questions as follows. Thanks!
Best Regards,
Jane Zhou
|
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.