- 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:
-
Integrations
-
Scripting and Coding

- 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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 05:18 AM
I'm guessing that the date comparison if statements are never being entered. On your source table is u_actual_start_date a string? If so you will need to convert it to a glidedate to do the comparison.
Maybe try something like this and see if that helps the comparison process.
var date = new GlideDate();
date.setValue(source.u_actual_start_date);
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_ScopedGlideDateSetValue_String
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 08:41 AM
Hey Tony - THank you for your recommendation unfortunately the value is still appearing as undefined

- 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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2019 10:50 AM
worked thanks!