The CreatorCon Call for Content is officially open! Get started here.

Add the duration variable to date and time variable and populat the end date value in string var

Community Alums
Not applicable

Hi Team,

 

I have created variable's in catalogs

 

1 start date - Date and time type variable

2 required time - Duration type variable

3 End time -  String type.

 

I need to add the duration and date and time variables. And populate the end time in string variable

 

I tried below script but its not working

 

Script inculde

var UtilsAjax = Class.create();
UtilsAjax.prototype = {
    initialize: function() {
    },
endtime: function() {
         var selected_date = new GlideDate();
         selected_date.setDisplayValue(this.getParameter('sysparm_Date'));
      //   var current = new GlideDate();

      var radio_button = this.getParameter('sysparm_Duration');
        //var start_date = this.getParameter('sysparm_Date');
         var start_check = gs.dateDiff(selected_date,radio_button, true);

       


         return start_check;
    },
    type: 'UtilsAjax'
};
 
Client script
 
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var duraton = g_form.getValue('duration');
var start_date = g_form.getValue('start');
var ga = new GlideAjax('UtilsAjax');
        ga.addParam('sysparm_name''endtime');
        ga.addParam('sysparm_Date', start_date);
        ga.addParam('sysparm_Duration',duraton);
        ga.getXML(CheckDateValidation);
    }

function CheckDateValidation(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);
   
}
 
Can you please check code
 
Thank you 
Challa reddy
3 REPLIES 3

HrishabhKumar
Kilo Sage

Hi @Community Alums ,

I've done some modification in your client script and script include, try them and see if it helps:

Script include:

var UtilsAjax = Class.create();
UtilsAjax.prototype = {
    initialize: function() {
    },
    
    endtime: function() {
        var selected_date = new GlideDateTime();
        selected_date.setDisplayValue(this.getParameter('sysparm_Date'));
 
        var duration = parseInt(this.getParameter('sysparm_Duration'), 10); // Assuming duration is in minutes
 
        selected_date.addMinutes(duration);
        
        return selected_date.getDisplayValue();
    },
 
    type: 'UtilsAjax'
};

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    
    var duration = g_form.getValue('duration');
    var start_date = g_form.getValue('start');
    
    var ga = new GlideAjax('UtilsAjax');
    ga.addParam('sysparm_name', 'endtime');
    ga.addParam('sysparm_Date', start_date);
    ga.addParam('sysparm_Duration', duration);
    
    ga.getXML(CheckDateValidation);
}
 
function CheckDateValidation(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    
    alert(answer);
    g_form.setValue('end_time', answer);
}

 

 

Thanks.

Hope this helps.

If my response turns useful please mark it helpful and accept solution.

Community Alums
Not applicable

@HrishabhKumar ,

 

Thank you for help.

I am using above script . But getting null value.

 

SivanandaReddy_0-1720438749125.png

Please help me on this error

 

Thank you

Sivananda

Community Alums
Not applicable

@HrishabhKumar Can you please help me on that