- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2024 09:38 AM
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 .
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2024 10:41 AM - edited 09-02-2024 10:41 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2024 10:41 AM - edited 09-02-2024 10:41 AM
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.