Difference between revisions of "Adding a given number of days to a date based on the value of a dropdown"

From SmartWiki
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
__NOTOC__
 +
{{JavaScript Syntax}}
 
==Problem==
 
==Problem==
 
A date must be displayed which is a number of business days after a date shown in an existing field. The number of days to be added will vary depending on the value of a [[Custom Field Type: Select One – Combo Box|dropdown field]] elsewhere on the page.
 
A date must be displayed which is a number of business days after a date shown in an existing field. The number of days to be added will vary depending on the value of a [[Custom Field Type: Select One – Combo Box|dropdown field]] elsewhere on the page.
Line 5: Line 7:
 
Create a [[Custom Field Type: Special – Calculated Value|Special – Calculated Value]] custom field with expressions equivalent to the following:
 
Create a [[Custom Field Type: Special – Calculated Value|Special – Calculated Value]] custom field with expressions equivalent to the following:
  
===Where the date to be added to is a custom field with a [[custom field id]] of 12345 and the dropdown list is named ''Client Category''===
+
===Where the date to be added to is a custom field with a [[Custom Field ID]] of 12345 and the dropdown list is named ''Client Category''===
  [Client Category]=='Regular'?busdateadd(frm.cf_12345.value,10):[Client Category]=='Under Investigation'?busdateadd(frm.cf_12345.value,5):[Client Category]=='Special'?busdateadd(frm.cf_12345.value,30):'0000-00-00'
+
<pre style="white-space: pre-wrap;
 +
  white-space: -moz-pre-wrap;
 +
white-space: -pre-wrap;
 +
white-space: -o-pre-wrap;
 +
word-wrap: break-word;">[Client Category]=='Regular'?busdateadd(frm.cf_12345.value,10):[Client Category]=='Under Investigation'?busdateadd(frm.cf_12345.value,5):[Client Category]=='Special'?busdateadd(frm.cf_12345.value,30):'0000-00-00'</pre>
 +
 
 
===Where the date to be added to is the [[standard field]] "Start Date" and the dropdown list is ''Time Line''===
 
===Where the date to be added to is the [[standard field]] "Start Date" and the dropdown list is ''Time Line''===
  [Time Line]=='Regular'?busdateadd(frm.startdate.value,10):[Time Line]=='Under Investigation'?busdateadd(frm.startdate.value,5):[Time Line]=='Special'?busdateadd(frm.startdate.value,30):'0000-00-00'
+
<pre style="white-space: pre-wrap;
 
+
white-space: -moz-pre-wrap;
The
+
white-space: -pre-wrap;
 +
  white-space: -o-pre-wrap;
 +
word-wrap: break-word;">[Time Line]=='Regular'?busdateadd(frm.startdate.value,10):[Time Line]=='Under Investigation'?busdateadd(frm.startdate.value,5):[Time Line]=='Special'?busdateadd(frm.startdate.value,30):'0000-00-00'</pre>
  
 +
The above calculations follow the rules:
 +
* If the dropdown field is set to "Regular," the value of this field will be 10 business days after the specified date field
 +
* If the dropdown field is set to "Under Investigation," the value of this field will be 5 business days after the specified date field
 +
* If the dropdown field is set to "Special," the value of this field will be 30 business days after the specified date field
 +
* If the dropdown field is set to none of the above values, the value of this field will be '0000-00-00'
  
 
==See Also==
 
==See Also==

Latest revision as of 15:47, 13 May 2014

This feature uses JavaScript syntax
Text code javascript.gif

Problem

A date must be displayed which is a number of business days after a date shown in an existing field. The number of days to be added will vary depending on the value of a dropdown field elsewhere on the page.

Solution

Create a Special – Calculated Value custom field with expressions equivalent to the following:

Where the date to be added to is a custom field with a Custom Field ID of 12345 and the dropdown list is named Client Category

[Client Category]=='Regular'?busdateadd(frm.cf_12345.value,10):[Client Category]=='Under Investigation'?busdateadd(frm.cf_12345.value,5):[Client Category]=='Special'?busdateadd(frm.cf_12345.value,30):'0000-00-00'

Where the date to be added to is the standard field "Start Date" and the dropdown list is Time Line

[Time Line]=='Regular'?busdateadd(frm.startdate.value,10):[Time Line]=='Under Investigation'?busdateadd(frm.startdate.value,5):[Time Line]=='Special'?busdateadd(frm.startdate.value,30):'0000-00-00'

The above calculations follow the rules:

  • If the dropdown field is set to "Regular," the value of this field will be 10 business days after the specified date field
  • If the dropdown field is set to "Under Investigation," the value of this field will be 5 business days after the specified date field
  • If the dropdown field is set to "Special," the value of this field will be 30 business days after the specified date field
  • If the dropdown field is set to none of the above values, the value of this field will be '0000-00-00'

See Also