Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Calculated Values - Setting current date

I have 3 Timestamp fields that needs to set to current date based on the 3 values (1,2,3) selection in a enumerated field.
For example-
When i select 1 the first date field should be set to current date.
When i select 2 the second date field should be set to current date (Without losing the value for first field)
When i select 3 the third date field should be set to current date. (Without losing the value for first or second field)

Now the problem is when i select 1 the first date field gets set to current date which is as expected. When i select 2 the second date field gets set to current date but here I also lose the value for the first date field which was set when i selected 1. same thing happens when i select 3.

Any advice on how can achieve this without losing any values ?

Below is the script i am using-



dojo.provide("com.example.script.CurrDateForOne");
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings

(function() {
    dojo.declare("com.example.script.CurrDateForOne", null, {

        getValue: function(attribute, workItem, configuration) {
           
            //get the current date
            var date=new Date();
            var currDate=dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true});
            console.log("Date: "+currDate);
           
                         
           
            //get the current status
            var status=workItem.getValue("com.example.team.workitem.fdreviewStatus");
            console.log("Status: "+status);
           
           
            if(status === "com.example.team.workitem.enum.ReviewStatus.literal.l3"){               
                return currDate ;
            }
        }
    });
})();

0 votes


Accepted answer

Permanent link
HI Akshay,

I modified the conditions a bit and it seems to be working, check the below revised code :

dojo.provide("com.example.script.CurrDateForOne");
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings
 
(function()
{
     dojo.declare("com.example.script.CurrDateForOne", null,
    {
 
        getValue: function(attribute, workItem, configuration)
         {
            var date=new Date();
            var currDate=dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true});
            
            var status=workItem.getValue("com.example.team.workitem.fdreviewstatus");
                      
             if (attribute === "stat1date" && status === "reviewStatusEnum.literal.l2")
             {
                 return currDate;
             }
             else
             {
                 return workItem.getValue("stat1date");
             }

        }
     });
 })();


Guess you plan to have a total of three scripts, each watching over their attribute values in the condition internally.
I tried to get one script for all three attributes but it seemed to be tricky.. three separate scripts do the trick easily instead...

hope this helps.
Akshay Panchakshari selected this answer as the correct answer

0 votes


One other answer

Permanent link
Hi Dinesh

Thank you for the reply. Yes i tried with above script it works perfectly fine!!
Another way to do the same would be as follows-


/*******************************************************************************/
dojo.provide("com.example.script.CurrDateForApprovedDPL");
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings

(function() {
    dojo.declare("com.example.script.CurrDateForApprovedDPL", null, {

        getValue: function(attribute, workItem, configuration) {
           
            console.log("CurrDateForApprovedDPL");
           
            var resultDate= null;

           
            //Current value set in date field
            var currDateValue=dojo.date.stamp.fromISOString(workItem.getValue(attribute));       
            console.log("Current value set is : "+currDateValue);
           
            //get the current date
            var date=new Date();
            var currDate=dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true});
           
            //get the current status
            var status=workItem.getValue("com.example.team.workitem.dplreviewstatus");
            console.log("Status: "+status);
           
            if(currDateValue != null){
                resultDate=currDateValue;
            }
            else{
                if(status === "com.example.team.workitem.enum.ReviewStatus.literal.l5"){               
                    resultDate=currDate;
                }
            }
            return resultDate;   
           
           
        }
    });
})();

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,943

Question asked: Sep 02 '16, 3:14 a.m.

Question was seen: 2,647 times

Last updated: Sep 06 '16, 2:45 a.m.

Confirmation Cancel Confirm