Servicenow

HARSHA GOWDA R
Tera Contributor

Can anyone help me with this code , Below i attached 2 files .So if i select the date for example from 02-01-2024(effective date) to 12-01-2024(effective date) so in the end point its triggering with same year but with diff date and month , can anyone look at the script and files and guide where i went wrong?
Onchange 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
 ga.addParam('sysparm_effective_date', newValue);
 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);
     }
 }

Script Include
var iamServiceAccountOnboardingUtils = Class.create();
iamServiceAccountOnboardingUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    calculateEndDate: function() {
        var effectiveDate = this.getParameter('sysparm_effective_date');
        var endDate = new GlideDateTime(effectiveDate);
        endDate.getDate().getByFormat("dd-MM-yyyy");
        endDate.addYearsLocalTime(1);
        return endDate.getValue();
    },

 type: 'iamServiceAccountOnboardingUtils'
   
});
10 REPLIES 10

What is the last state of the issue?