ATF - Custom Step Configuration4 - Get Future/Prior Date from current date
ATF - Custom Step Configuration4 - Get Future/Prior Date from current date
Hi,
This Step Config gets Future/Prior Date from current date as per user datetime format
Step Environment: Server Independent
Category: Server
Input variable:
Output variable:
Description generation script:
function generateDescription(step) { // the global variable 'step' represents the current glide record var description = gs.getMessage("Future/Prior Date from current date as per user datetime format"); return description;}
generateDescription(step);
Step execution script:
(function executeStep(inputs, outputs, stepResult, timeout) {
var days = inputs.u_future_or_prior_days_to_currentdate;
var MESSAGE_KEY_SUCCESS = "Success: Date information is passed to the output variable";
function logic() {
var timeFormat = gs.getSession().getUser().getDateFormat(); var date = new Date(); date.setDate(date.getDate() + days); var yyyy = date.getFullYear().toString(); var mm = (date.getMonth() + 1).toString(); // getMonth() is zero-based
var dd = date.getDate().toString();
if (mm <= 9) { mm = "0" + mm;
}
if (dd <= 9) { dd = "0" + dd;
}
timeFormat = timeFormat.replace('dd', dd).replace('MM', mm).replace('yyyy', yyyy);
timeFormat = timeFormat + " 00:00:00";
outputs.u_date = timeFormat; stepResult.setOutputMessage(MESSAGE_KEY_SUCCESS);
stepResult.setSuccess();
} logic();
}(inputs, outputs, stepResult, timeout));
Labels:
https://www.servicenow.com/community/developer-articles/atf-custom-step-configuration4-get-future-prior-date-from/ta-p/2300285
