Date/Time script on Record Producer

booher04
Tera Guru

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");

}

18 REPLIES 18

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');
		}
	}
}

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. 

did you create the script include that is in the blog link I included?

I did. sorry for the delay, I had a deadline on another item I had to finish up.  

can you share the code in the client script.