jas101
Tera Expert

Hi all, really hope someone is able to help as I would love to get this working.

Basically on our CHG form Schedule tab we have the OTB date/time fields: 'Planned start' and 'Planned end'

We want to add a field for 'change duration', so this would then get added to the 'Planned start' in order to automatically set value 'Planned end' (which we would then make read-only).

I have created the above script include and have created a corresponding onChange client script but the value is not being set and the alert is always saying 'null'.

Also I'm not sure what the best field type is for our new 'change duration' field - ideally we'd want the user to specify in hours. I've tried string, decimal and duration type fields. One which is able to force a consistent format would obviously be preferred.

Current client script is below (the onChange field name is set to 'Duration 2'). I know it currently says minutes, I have played with this in attempt to get it working also.

Many thanks for any help in advance,

DS

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
      var sdt = g_form.getValue('start_date'); //Choose the field to add time from  
      var addtime = g_form.getValue('u_duration_2'); //The amount of time to add  
      var addtype = 'minute'; //The time type.   Can be second, minute, hour, day, week, month, year.  
var ajax = new GlideAjax('ClientDateTimeUtils');  
      ajax.addParam('sysparm_name', 'addDateTimeAmount');  
ajax.addParam('sysparm_fdt', sdt);  
ajax.addParam('sysparm_addtime', addtime);  
ajax.addParam('sysparm_addtype', addtype);  
ajax.getXML(doSomething);  
 
  function doSomething(response){  
      var answer = response.responseXML.documentElement.getAttribute("answer");  
      //You could then take the new Date/Time answer and set the value of another field.  
      g_form.setValue('end_date', answer);
g_form.setReadOnly('end_date', 'true');
       
      alert(answer);  
}
}