The Zurich release has arrived! Interested in new features and functionalities? Click here for more

how add hours to the date type variable based on some duration field(duration field is some choices example 4 and 8 and 12)

rajasekahr
Tera Guru

Hi Team,

I wanted to add some extra hours based on the duration field to the date type variable. Please find my catalog client script and script include function code 

catalog client script:

var duration=g_form.getValue('ga_fc_duration');
    var date=g_form.getValue('ga_fc_date_time');
    //alert('dt' +dt);
    var ga1 = new GlideAjax('CatalogDateFunctions');
    ga1.addParam('sysparm_name','DateAddDuration');
    ga1.addParam('sysparm_duration',duration);
     ga1.addParam('sysparm_date',date);
    ga1.getXML(function(resp) {
        var lockTime = resp.responseXML.documentElement.getAttribute("answer");

        alert('lockTime' + lockTime);
        g_form.setValue('ga_fc_relock_date', lockTime);

    });

 

script include function code:

DateAddDuration: function() {
      var duration = this.getParameter('sysparm_duration');
        var date = this.getParameter('sysparm_date');
      var day = new GlideDateTime();
        day.setDisplayValue(date);
        var hours = 60 * 60 * duration;
        day.addSeconds(hours);
        return day.getDisplayValue();
    },

 

1 REPLY 1

Yousaf
Giga Sage

Hi Rajasekahr,

Please check this link:
https://community.servicenow.com/community?id=community_question&sys_id=06d90329db5cdbc01dcaf3231f96...

Mark Correct or Helpful if it helps.

Thanks,
Yousaf


***Mark Correct or Helpful if it helps.***