
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2019 11:58 AM
I want to make it so that when someone click on the UI Action Implement before the start time it gives them an error message. I'm not sure they best way to code date/time comparisons in a UI action. What would be the best way to do this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 07:29 AM
Hello thanks for you help. I got this working by using a script include I had for validating date/times on client scripts for catalog items.
function moveToImplement(){
var validTime = new GlideAjax ("ClientDateTimeUtils");
validTime.addParam('sysparm_name', 'getNowDateTimeDiff');
validTime.addParam('sysparm_fdt', g_form.getValue('start_date'));
validTime.getXMLAnswer(function(dateDiff){
if (dateDiff > 0){
alert('You cannot implement this change before the approved change windows. ' + g_form.getValue('start_date'));
}
else {
var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
ga.addParam("sysparm_name", "getStateValue");
ga.addParam("sysparm_state_name", "implement");
ga.getXMLAnswer(function(stateValue) {
g_form.setValue("state", stateValue);
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
});
}
});
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 07:11 AM
You have an onClick function that only runs client side code, once that has completed the gsftsubmit line calls back to the action name which then runs the server side code.
The code you put in the function called in the onClick must be client supported API, using glidesystem, the current object and dateDiff won't work in that function.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 07:29 AM
Hello thanks for you help. I got this working by using a script include I had for validating date/times on client scripts for catalog items.
function moveToImplement(){
var validTime = new GlideAjax ("ClientDateTimeUtils");
validTime.addParam('sysparm_name', 'getNowDateTimeDiff');
validTime.addParam('sysparm_fdt', g_form.getValue('start_date'));
validTime.getXMLAnswer(function(dateDiff){
if (dateDiff > 0){
alert('You cannot implement this change before the approved change windows. ' + g_form.getValue('start_date'));
}
else {
var ga = new GlideAjax("ChangeRequestStateHandlerAjax");
ga.addParam("sysparm_name", "getStateValue");
ga.addParam("sysparm_state_name", "implement");
ga.getXMLAnswer(function(stateValue) {
g_form.setValue("state", stateValue);
gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
});
}
});
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}