date populate

Ketan Pandey
Tera Expert

HI All,

 

Please help for this

 

I have a date and time field on  "Site Visit ETR" (Date andTime field),On select of the Urgency,The "Site Visit ETR" to be populated with Current Data + 3 days. Please guide how to do this from client script. I want to develope this for workspace . 

g_user_date_time_format  is not supported for wprkspace

 

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

Hi @Ketan Pandey,

 

I've created a client script that runs onChange for a field on my table. The script follows:

 

 

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

	var ga = new GlideAjax('AddDaysToCurrentDate');
	ga.addParam('sysparm_name', 'addDays');
	ga.addParam('sysparm_days_to_add', 3);
	ga.getXMLAnswer(getResponse);

	// callback function for returning the result from the script include
	function getResponse(response) {
//		alert ('New Date = ' + response);
		var newDate = response;
		g_form.setValue('u_expected_date_time', newDate);
	}
   
}

 

change the "u_expected_date_time" field name to your field name. And a script include to do the date related calculation follows:

 

 

var AddDaysToCurrentDate = Class.create();
AddDaysToCurrentDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	addDays: function() {
		var daysToAdd = this.getParameter("sysparm_days_to_add");
//		gs.info('AddDaysToCurrentDate: adding ' + daysToAdd + ' days');
		var gdt = new GlideDateTime();
//		gs.info('AddDaysToCurrentDate: current datetime: ' + gdt);
		gdt.addDays(daysToAdd);
//		gs.info('AddDaysToCurrentDate: returning gdt result: ' + gdt);
		return gdt.toString();
	},

    type: 'AddDaysToCurrentDate'
});

 

The script include is named "AddDaysToCurrentDate" and has 'Client callable' checked.

View solution in original post

1 REPLY 1

Bert_c1
Kilo Patron

Hi @Ketan Pandey,

 

I've created a client script that runs onChange for a field on my table. The script follows:

 

 

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

	var ga = new GlideAjax('AddDaysToCurrentDate');
	ga.addParam('sysparm_name', 'addDays');
	ga.addParam('sysparm_days_to_add', 3);
	ga.getXMLAnswer(getResponse);

	// callback function for returning the result from the script include
	function getResponse(response) {
//		alert ('New Date = ' + response);
		var newDate = response;
		g_form.setValue('u_expected_date_time', newDate);
	}
   
}

 

change the "u_expected_date_time" field name to your field name. And a script include to do the date related calculation follows:

 

 

var AddDaysToCurrentDate = Class.create();
AddDaysToCurrentDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	addDays: function() {
		var daysToAdd = this.getParameter("sysparm_days_to_add");
//		gs.info('AddDaysToCurrentDate: adding ' + daysToAdd + ' days');
		var gdt = new GlideDateTime();
//		gs.info('AddDaysToCurrentDate: current datetime: ' + gdt);
		gdt.addDays(daysToAdd);
//		gs.info('AddDaysToCurrentDate: returning gdt result: ' + gdt);
		return gdt.toString();
	},

    type: 'AddDaysToCurrentDate'
});

 

The script include is named "AddDaysToCurrentDate" and has 'Client callable' checked.