It's all about the answers!

Ask a question

How can we make an RTC script (Js/Dojo) run periodically and let it set a specific attribute value directly (with out need to open a work item, change a specific value and save it)?


Abdelrahman Hassan (199) | asked Nov 27 '17, 3:34 a.m.
edited Nov 27 '17, 3:59 a.m.

I have a script which gets the difference between Current Date and Due Date. The script returns the number of days and it only runs if the Due Date has changed manually in the work item.

I need to let it run every day automatically (for example at 12:00 AM).

I also need to let the script save the returned value (the number of days) to a specific attribute directly when the script runs (without need to open the work item and changing the due date manually, then saving it).

Accepted answer


permanent link
Ralph Schoon (57.1k23642) | answered Nov 27 '17, 5:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Basically you can't and you also should not even try.

As explained in How should I ask a question in the Forum if I want to receive useful answers? you describe a solution for some problem and ask how to implement that solution. You should however state the requirement/the business problem and not your considered implementation of a solution.

I would be very concerned about a solution that has to update a lot of work items every day. Especially if it to only compute the difference between a due date and the current date and potentially do something (e.g. send an e-mail). This sounds like a terrible idea and I would not even suggest ways to implement it, unless I know the business case. This is likely rather something that needs to be implemented in reporting or maybe some other mechanism that does NOT update the work items. 

Geoffrey Clemm selected this answer as the correct answer

Comments
Abdelrahman Hassan commented Nov 27 '17, 4:56 p.m.

Ralph - Thank you for your comment. I will take care of the question guideline in the future.

The case is that we need to set another attribute based to how far we are from the due date. We have an enumeration attribute "Health Status" with three values (Red, Green, and Amber) and we would pick up one value (Color) based on how many days between current and due dates.

The script would tun only if we changed the Due Date, so I was looking for a way to do that calculation automatically and set the Health Status attribute.

I'm adding the script in another comment.


Abdelrahman Hassan commented Nov 27 '17, 4:58 p.m.

Please find the script below:
// If Due Date is from 0 to 7 days behind the Current Date (today’s date), then the “Health Status” field will show “Amber”.
// If Due Date is more than 7 days behind the Current Date (today’s date), then the “Health Status” field will show “Red”
// If Current Date (today’s date) behind the Due Date, then the “Health Status” field will show “Green”

dojo.provide("com.example.dateDifference");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");

 (function() {
    dojo.declare("com.example.dateDifference", null, {
    getValue: function(attributeId, workItem, configuration) {
 
// the script will continue in the following comment


Abdelrahman Hassan commented Nov 27 '17, 5:07 p.m.

try {
var dueDate = dojo.date.stamp.fromISOString(workItem.getValue("dueDate"));  
var dayDiff = dojo.date.difference(dueDate);

if (dayDiff < 0)   { return "Health.literal.l2"; }
else if (dayDiff > 7) { return "Health.literal.l1"; }
else { return "Health.literal.l3"; }
}
catch(err) {
var txt;
txt="There was an error on this page.\n\n";
txt+="Error description: " + err.message + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
}
}
});
})();


Ralph Schoon commented Nov 27 '17, 11:30 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You still talk about an implementation and not the requirement which is to be able to report and query the work items status with respect to being over due.


A calculated value is not the best solution for this and certainly not if you calculate it every night.

You should create work item queries or reports to show the work items that are over due there is also a due date notifier  https://rsjazz.wordpress.com/2015/10/16/due-date-notifier-an-asynchronous-task-example/ . 


Abdelrahman Hassan commented Nov 28 '17, 2:02 a.m.

Ok, thank you for your help.


Ralph Schoon commented Nov 28 '17, 2:24 a.m. | edited Nov 28 '17, 7:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sorry, no time today to spend on this. Look into reporting and work item queries if you can create reports/queries for this work item. Unfortunately there is no way to implement an attribute that is always calculated when the work item is accessed by a report or query.

You can only try to use the due date and the current date and try to calculate the difference.

showing 5 of 6 show 1 more comments

One other answer



-1
permanent link
bahaddin alnatour (92) | answered Nov 27 '17, 5:34 a.m.

I suggest to use client side extension to calculate the difference and export it as a runnable jar file then run it using a windows task scheduler everyday @12 am.

BTW , a lot of Client side extensions example provided by JAZZ.net you can get as an example HERE


Comments
Ralph Schoon commented Nov 27 '17, 5:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I suggest to not do something like that if there are no really good reasons. It is likely that this is just a very messy solution for some business problem that should be solved otherwise. You simply don't automatically update a date attribute every day, period.


Abdelrahman Hassan commented Nov 27 '17, 5:04 p.m.

Bahaddin - Thank you for your help, much appreciated.

Your answer


Register or to post your answer.