- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 05:44 AM
Hi,
I want that on change_request table, planned start date should always be 24hrs ahead of current time.
I have done this successfully using Business Rule, But I have to do this using Client Script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var start = g_form.getValue('start_date');
var dttype = 'hour';
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDateTimeDiff');
ajax.addParam('sysparm_fdt', start);
ajax.addParam('sysparm_difftype', dttype);
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer >= 1)
{g_form.addErrorMessage('Selected time should be more than 24 hours of current time');
}
}
it is not working. Can someone help with the code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2019 06:55 AM
I see, if you only want to write in client script. You can using pure javascript in stead of ajax call.
Below is the sample: You write this in your client script then you should able to get day ago date and from there u can continue your checking logic.
var d = new Date();
d.setDate(d.getDate() - 1);
alert(d.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 07:14 AM
can you please check my code that I have updated with the question?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 07:26 AM
First, when do you want to set the planned start date? When some other field changes or when the change record is first created? I was thinking this was on a new change record, thus OnLoad, not on Change. You can do on change, but you need to determine what must change for you to reset/set the planned start date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 08:29 AM
I want that when user who is filling the new change request form tries to set the planned start date field to a date less than 24 hours ahead, the value is not submitted and a message is displayed that it is less than 24 hrs ahead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 07:35 AM
Are your script "ClientDateTimeUtils" agreed to Ajax class?
Your class for AJAX should be something like below
var ClientDateTimeUtilsAjax= Class.create();
ClientDateTimeUtilsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
--- contents ---
type: 'ClientDateTimeUtilsAjax'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2019 08:24 AM
The format you are saying is for Script include. I am writing a Client Script