Servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:52 AM
Can anyone help me with this code?It should work on service portal with scoped application. Let me tell the error what I am facing, the end date is populating one day prior to effective date that should not happen, say if I select 29-01-2024 in the effective date the end date should be 29-01-2025 with one year more that effective date.
Script Include-
var iamServiceAccountOnboardingUtils = Class.create();
iamServiceAccountOnboardingUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
calculateEndDate: function() {
var effectiveDate = this.getParameter('sysparm_effective_date');
var end_date = new GlideDateTime();
end_date.setNumericValue(effectiveDate);
end_date.addMonthsLocalTime(12);
return end_date.getDate();
},
type: 'iamServiceAccountOnboardingUtils'
});
Client Script-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('iamServiceAccountOnboardingUtils'); //scriptinclude name
ga.addParam('sysparm_name', 'calculateEndDate'); //function name
var date_number = getDateFromFormat(newValue + ' 00:00:00', g_user_date_time_format);
ga.addParam('sysparm_effective_date', date_number);
ga.getXML(answerCallback); // Define the callback function
}
function answerCallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
// Set the calculated end date in the end date field
g_form.setValue('end_date', answer);
}
}