- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 12:32 PM
I've got an Asset table with a Purchase Date field.
I need to add a new field called Lifecycle Expiration.
I then need to take the Purchase Date, add 5 years, then put that date in the Lifecycle field (read only field).
How do i do this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 05:17 PM
Here's the code that I used. In my example, I subtracted a week, but the logic is the same and you can just tweak it to your own needs. Note that I'm adding 1 to the month because January returns as 0.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var start_date = new Date(g_form.getValue('SOURCE VARIABLE'));
start_date.setDate(start_date.getDate() - 7);
var month = start_date.getMonth() + 1;
var day = start_date.getDate();
var year = start_date.getFullYear();
var work_start;
if(month < 10){
month = "0" + month;
}
if(day < 10){
day = "0" + day;
}
work_start = month + "-" + day + "-" + year;
g_form.setValue('DESTINATION VARIABLE', work_start);
}
Value('DESTINATION VARIABLE', work_start);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 12:40 PM
Hi Anthony
You can have the new Lifecycle field as a calculated field. By taking the purchase date field (e.g. current.date_field_name), creating a new GlideDateTime object from that and then use the GlideDateTime API for the actual calculation, then just return the new value.
Hope this helps
Shahid

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 12:43 PM
Hi Anthony,
I've done similar things in the past in a client script. First I follow the scripting suggestion here: javascript - Add year to todays date - Stack Overflow
The problem is that will return a date/time. I just parsed it into an array to get the information I wanted and manipulated it into the appropriate order. May not be the most effective way to do it, but it got the job done.
I can get you example code, if you'd like, a little later.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 12:48 PM
if you could post that script later please

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2017 12:51 PM
Sure thing!