0
Hello Everyone,

1. I have a requirement to create a field named "Age".
2. The end user wants: 'Current date' minus 'Submit date'. (a virtual field)
3. This field 'Age' has to show the number of days the issue is active
4. This field has to reflect this numeric value in whatever state the issue is in.

Please let me know if you can offer any help.

Thank you,
Patrick

Accepted Answer

Monday, May 15 2017, 05:20 PM - #Permalink
0
Thanks everyone for the help. I got this working today with some small changes.


Placed a ‘Text’ (Composer, Other Controls) onto the State form.
Named it: ActiveDays
Placed another 'Text' for the name to: Days Active (or whatever you prefer)
Added form action: ActiveDays
'When’ this form is loaded
'If' ActiveDays' control is visible
'Then' execute javascript

With this code:

var dateStart = GetFieldValue("SUBMITDATE");
var closedate = GetFieldValue("CLOSEDATE");
var dateEnd = (closedate) ? closedate:new Date();
var dateStart_ms = dateStart.getTime();
var dateEnd_ms = dateEnd.getTime();
var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
var days = Math.floor((dateEnd_ms - dateStart_ms) / oneDay);
SetFieldValue("ActiveDays", days.toString());
The reply is currently minimized Show
Responses (5)
  • Accepted Answer

    Saturday, May 13 2017, 11:03 PM - #Permalink
    0
    The field is a bad idea. Try a listing report. On the "Additional Options" tab add a calculation column:
    Age = Now - Submit date

    SBM has several other types of reports that can classify and group items by age.
    The reply is currently minimized Show
  • Accepted Answer

    Monday, May 15 2017, 08:12 AM - #Permalink
    0
    I agree with Paul that creating a field is not a good idea, as keeping it up-to-date is impractical. If you merely need to display ‘Days Active’ in a report, then a calculated field is the way to go. However, it you want to display a ‘virtual’ (not-saved) value on the state form for an item, you can do the following:
    Place an ‘EditBox’ (Composer, Other Controls) onto the form.
    Name it: ActiveDays
    Select the Label, and set Display text to: Days Active (or whatever you prefer)
    Add a form action: ‘When’ this form is loaded
    In the ‘Then’ section, choose execute javascript, and implement like so:
    var dateStart = GetFieldValue("SUBMITDATE");
    var closedate = GetFieldValue("CLOSEDATE");
    var dateEnd = closedate != "" ? closedate : new Date();
    var utc1 = Date.UTC(dateStart.getFullYear(), dateStart.getMonth(), dateStart.getDate());
    var utc2 = Date.UTC(dateEnd.getFullYear(), dateEnd.getMonth(), dateEnd.getDate());
    var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
    var days = Math.floor((utc2 - utc1) / oneDay);
    SetFieldValue("ActiveDays", days.toString());
    The implementation assumes you have added the Close Date, optional system field to your schema. The number of says is the lesser of the difference between Close Date and Submit Date, or Now and Submit Date.
    The reply is currently minimized Show
  • Accepted Answer

    Monday, May 15 2017, 10:21 AM - #Permalink
    0
    Thank you Steve. I keep getting "Object doesn't support property or method 'getFullYear'
    The reply is currently minimized Show
  • Accepted Answer

    Monday, May 15 2017, 03:27 PM - #Permalink
    0
    Patrick,

    Make sure the Close Date field is actually displayed on your form or you will get the error you're getting.
    The reply is currently minimized Show
  • Accepted Answer

    Friday, June 09 2017, 03:09 PM - #Permalink
    0
    another option would be to create a text field named age and create a notification that repeats every 24 hours. on that notification set it to call an appscript that will calculate the age and update your items age field.
    The reply is currently minimized Show
Your Reply

Recent Tweets