Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

set date/time - specific time in the past

matthew_magee1
Giga Guru

Hi all,

I know various flavors of this question have been asked before; yet I can't seem to find a simple solution.

I am running Geneva.

On the CHG form, I have 2 date/time fields:

  1. Start Date (start_date)
  2. Notification Date (u_notification_date)

If the user selects 5/8/17 as the start date, I'd like the Notification date to automatically default to the date before @ 14:30:00. In this example, the Notification Date would default to 5/7/17 @ 14:30:00

Any help is greatly appreciated

1 ACCEPTED SOLUTION

oharel
Kilo Sage

Hi Matthew,



If both are date/time, this is what works for me:


onChange client script:


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue === '') {


  return;


  }



  //Type appropriate comment here, and begin script below


  g_form.clearValue('u_notification_date');


  var start = g_form.getValue('start_date');


 


  //var ga = new GlideAjax('')


  var ga = new GlideAjax('setMyDate');


  ga.addParam('sysparm_name','getDateTime');


  ga.addParam('sysparm_start',start);


  ga.getXML(ParseTheTime);


   


  function ParseTheTime(response) {


  var answer = response.responseXML.documentElement.getAttribute("answer");


  g_form.setValue('u_notification_date',answer);



  }


}




script include:


var setMyDate = Class.create();


setMyDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  getDateTime : function() {



  var start = this.getParameter('sysparm_start');


  var days = 1;



  var strDate = start.split(' ')[0];


  var vDate =   new GlideDateTime(strDate);


  vDate.addDays(-days);


  var vDateStr = vDate.getDate() + ' 14:30:00';


  return vDateStr;



  },


      type: 'setMyDate'


});



Based on amlanpal 's script in another post.


harel


View solution in original post

10 REPLIES 10

Yes, that what I did in my test instance too, but was looking for a setDisplayValue() way to do it more elegantly.


Anyway, good for you