Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 05:01 AM
Im calculating whether the dates coming within the imports are today or later and based upon that value it'll determine what to set the field map too, but I am continuing to receive undefined:
answer = (function transformEntry(source) {
var today = new GlideDate();
var stage;
var year = today.addYears(1);
if (source.u_date_type =="Construction Start") {
var date = source.u_actual_start_date;
if (date >= today) {
stage = "Under Construction";
}
} else if (source.u_date_type =="Reopen Date") {
var dates = source.u_actual_start_date;
if (dates >= today) {
stage = "Re-opened";
} else if (dates >= year) {
stage = "Complete";
}
}
return stage; // return the value to be put into the target field
})(source);
Solved! Go to Solution.
Labels:
- Labels:
-
Integrations
-
Scripting and Coding
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 11:23 AM
Try this
answer = (function transformEntry(source) {
var stage;
var today = new GlideDateTime();
var year = new GlideDateTime();
year.addYears(1);
var actual = new GlideDateTime(source.u_actual_start_date);
var diff = gs.dateDiff(today, actual, true);
if (source.u_date_type =="Construction Start") {
if (diff >= 0) {
stage = "Under Construction";
}
} else if (source.u_date_type =="Reopen Date") {
//Update the below logic as the above one
var dates = source.u_actual_start_date
if (dates >= today) {
stage = "Re-opened";
} else if (dates >= year) {
stage = "Complete";
}
}
return stage; // return the value to be put into the target field
})(source);
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 11:35 AM
Try?
answer = (function transformEntry(source) {
var today = new GlideDate();
var stage;
var year = new GlideDate();
year.addYears(1);
if (source.u_date_type =="Construction Start") {
var date = source.u_actual_start_date;
if (date >= today) {
stage = "Under Construction";
}
} else if (source.u_date_type =="Reopen Date") {
var dates = source.u_actual_start_date;
if (dates >= today) {
stage = "Re-opened";
} else if (dates >= year) {
stage = "Complete";
}
}
return stage; // return the value to be put into the target field
})(source);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2019 05:17 AM
Thanks Prateek, unfortunately the stage is coming in as undefined