Examples: date + days and percents

Create several fields of the specified types:

  1. On the custom fields administration page click the "add custom field" button

     

  2. select the screens where you want to see the fields

     

     

  3. Then go to the field context configuration page

     

  4. Click on " Edit Formula field config"

     

  5. the interface opens for configuring the formula

     

     

End date - JBCF:Formula(date)

Calculate the "End Date" (date field) = "Start Date" (date field)+ "Test Length in Days" (number field)

Formula:

1 2 3 4 5 6 7 (function(){ var startDateCustomFieldId = 10200;//Date picker - Start Date var testDaysCustomFieldId = 10201;//Number field - Test Length in Days if(cfValues[startDateCustomFieldId] != null){ return cfValues[startDateCustomFieldId].time + cfValues.getOrDefault(testDaysCustomFieldId, 0)*24*60*60*1000 } })()

Prepare value for view:

1 2 3 if(formulaValue != null){ "" + formulaValue.date + "/" + (formulaValue.month+1) + "/" + (formulaValue.year-100) }

View:

1 $prepareFormulaValue

 

Aging Complete date - JBCF:Formula(date)

Calculate the "Aging Complete Date"(date field) = "End Date" + "Aging Length" (number field)

Formula:

1 2 3 4 5 6 7 (function(){ var endDateCustomFieldId = 10011;//Formula date field - End Date var agingCustomFieldId = 10202;//Number field - Aging Length in Days if(cfValues[endDateCustomFieldId] != null){ return cfValues[endDateCustomFieldId].time + cfValues.getOrDefault(agingCustomFieldId, 0)*24*60*60*1000 } })()

Prepare value for view:

1 2 3 if(formulaValue != null){ "" + formulaValue.date + "/" + (formulaValue.month+1) + "/" + (formulaValue.year-100) }

View:

1 $prepareFormulaValue

 

% Complete - JBCF:Formula(number)

Calculate the "% Complete" (single line text field) = ("Today's Date" - "Start Date')/"Test Length in Days" - this should be a percentage. If the start date is in the future, it should be 0%; max number should be 100%.

 

Formula:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 (function(){ var startDateCustomFieldId = 10101;//Date picker - Start Date var testDaysCustomFieldId = 10200;//Number field - Test Length in Days return calculate() function calculate(){ var now = new Date() var start = cfValues[startDateCustomFieldId] var testingDays = cfValues[testDaysCustomFieldId] if(start == null || start.getTime() > now.getTime() || testingDays == null || testingDays == 0){ return 0 } else { return Math.min(100, Math.round(dayBetweenDates(start, now)/testingDays*100)) } } function dayBetweenDates(date1, date2){ return (date2.getTime() - date1.getTime())/ (1000 * 3600 * 24) } })()

View:

1 $formulaValue%

% Aged - JBCF:Formula(number)

Calculate the "% Aged" (single line text field) = ("Today's Date" - "End Date')/"Aging Length" - this should be a percentage. If the start date is in the future, it should be 0%; max number should be 100%

 

Formula:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 (function(){ var endDateCustomFieldId = 10011;//Formula date field - End Date var agingCustomFieldId = 10202;//Number field - Aging Length in Days return calculate() function calculate(){ var now = new Date() var end = cfValues[endDateCustomFieldId] var agingDays = cfValues[agingCustomFieldId] if(end == null || end.getTime() > now.getTime() || agingDays == null || agingDays == 0){ return 0 } else { return Math.min(100, Math.round(dayBetweenDates(end, now)/agingDays*100)) } } function dayBetweenDates(date1, date2){ return (date2.getTime() - date1.getTime())/ (1000 * 3600 * 24) } })()

View:

1 $formulaValue%

Result