Date/Time script on Record Producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2018 12:55 PM
I put a script together in the script section of a record producer. I have it working partially but can't seem to figure out what I'm missing. I want my field(u_outage_start) to not be allowed to be in the future. If it is, I want it to pop a message that says it can't be, and let the user correct the date on the portal page(record producer). Right now, it works, gives me the message but it still submits the catalog item and creates the incident with the incorrect outage date/time.
Here's the script:
var initialDate = new GlideDateTime(producer.u_outage_start).getDate();
var today = new GlideDateTime().getDate();
var diff = gs.dateDiff(today,initialDate, true);
if(diff > 0){
gs.addInfoMessage("Outage Start Date cannot be after today's date");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 07:35 AM
Following the Blog a couple of us mentioned I was able to do the following in my client script to get this to work.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name','getNowDate');
ajax.getXML(doSomething);
function doSomething(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var date = newValue.split(' ');
if (date[0] > answer){
alert('Start date cannot be in the future');
g_form.clearValue('issue_start');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 08:48 AM
Hmm.. ok great. I tried it with updating the variable to match mine but it didn't work. I'm going to have to look into it further.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2018 01:35 PM
did you create the script include that is in the blog link I included?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 01:31 PM
I did. sorry for the delay, I had a deadline on another item I had to finish up.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2018 05:05 AM
can you share the code in the client script.