"Hours" text not updating correctly.

Issue #319 resolved
Robert Anthony created an issue

I have four custom fields:

Date/Time Resolved (Date/Time Picker) customFieldId=10241 Date/Time Verified (Date/Time Picker) customFieldId=10242 MTTR (Single Line Text Field) MTTV (Single Line Text Field)

My workflows have many statuses, but only two really matter here.

On the Resolve transition, a tx screen appears where the user can update the "Date/Time Resolved" field and I have an advanced parsed text post function to update MTTR by comparing the created date and the Date/Time Resolved field on this transition. Here is the formula:

floor((datePart({10241}, LOCAL) - datePart({00009}, LOCAL)) / {DAY}) + "days " + (modulus(datePart({10241}, LOCAL) - datePart({00009}, LOCAL), {DAY}) / {HOUR}) + " hours"

The next transition window allows you to update "Date/Time Verified" field. On the transition the same kind of post function compares the "Date/Time Resolved Field" and the "Date/Time Verified Field" and populates the value to the MTTV field. Here is the formula: floor((datePart({10242}, LOCAL) - datePart({10241}, LOCAL)) / {DAY}) + "days " + (modulus(datePart({10242}, LOCAL) - datePart({10241}, LOCAL), {DAY}) / {HOUR}) + " hours"

Everything seems to be working correctly. However, the hours field is no longer updating it just sits at 0 for both MTTR and MTTV fields. When I was just updating the MTTR field with instructions provided by you, everything worked fine and hours were updating correctly as well as days. However as soon as I tried to do this on my own this happened! lol plz help.

Comments (5)

  1. Fidel Castro Armario repo owner

    Hi Robert,

    The problem with the current expression you are using is that function datePart() is rounding dates to whole days, and for that reason the hours term is always zero.

    Use this expression instead:

    floor(({10241} - {00009}) / {DAY}) + " days " + toString(modulus(({10241} - {00009}), {DAY}) / {HOUR}, 2) + " hours"
    

    I have also included function toString() in order to limit the number of decimals for the hour term to 2.

  2. Robert Anthony Account Deactivated reporter

    Thank you so much Fidel! Do I update both of my formulas, or just one?

  3. Fidel Castro Armario repo owner

    Yes, Robert, you should also modify your second expression. Assuming that Date/Time Verified is always greater (later) than Date/Time Resolved, then your expression should be:

    floor(({10242} - {10241}) / {DAY}) + " days " + toString(modulus(({10242} - {10241}), {DAY}) / {HOUR}, 2) + " hours"
    
  4. Log in to comment