Highlighted
Absent Member.
Absent Member.
13362 views

Dependent Dates


I need help setting dates to automatically fill in once I fill in "required" dates that I've created.

I have several dates dependent on several other dates/events.

For example, let's say my main event happens on 1/10/2014. Now, say I have events that now should fill in with automatic dates from that original date. Let's say one event is that main event date - 10 days and the second event is +10 after the main event date. So, they automatically should fill in to being 12/31/2013 and the other should go to 1/21/2014.

More complex, is that those date calculations can change based on the TYPE of main event. So, for example, I'll have two choices for main event: Hot and Cold

Well, on Hot, I need the prior dates to be + or - 10 and with Cold, I need the dates to be + or - 23 or something.

How can I get that all to work??
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.


You'll need to use a custom form if you want this to happen dynamically (as user is entering Main Event Date).

Add an Action:

When Main Event Date field changes value Then execute {some JavaScript}.

The Javascript to execute might look like this. I only did the "Before" field but you'll probably get the picture. Watch out for GetSatisfaction wrapping lines at exactly the wrong place 😞



// POC for:

// http://communities.serena.com/serena/topics/dependent_dates

// Current value of the Main Event field.

var dat_MainEventDate = GetFieldValue('Main Event Date') ;

if (dat_MainEventDate) {

// # of days to add to Main Event date

// depend on the Main Event type.

// Use a data-driven approach instead

// of a bunch of if/then/else stuff.

var obj_EvtOffset = {

'hot': {Before:-10 , After:+10} ,

'cold': {Before:-23, After:+23} ,

'default': {Before:0, After:0}

} ;

// The determining factor. If field is empty

// 'default' is returned, so use the 'default'

// entry from the lookup table.

var str_MainEventType =

GetFieldValue('TITLE','default').toLowerCase() ;

var dat_Before ;

// msec per day = 60 * 60 * 24 * 1000 = 86400000

// If Main Event Type is found in the lookup,

// do the math & set the field.

if (obj_EvtOffset[str_MainEventType]) {

// Repeat the next couple lines for "After" date.

dat_Before = new Date (dat_MainEventDate.valueOf() +

(obj_EvtOffset[str_MainEventType].Before * 86400000)) ;

SetFieldValue('Before Main Event' , dat_Before);

}

else {

// TODO: Warning for unexpected value in the

// determining factor field.

}

}

else {

// TODO: error handling :: Main Event Date returned null.

}

// The Action definition has the AddChangeCallback.


0 Likes
Highlighted
Absent Member.
Absent Member.


Paul,

I will totally try this. I appreciate your time and response. Thank you for the advice. I sincerely appreciate it!
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.