
- 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-10-2019 12:55 PM
it works the same way it work for business rule.
compare the dates
something similar
startdate();
function startdate() {
var tnow = gs.nowDateTime();
//gs.addInfoMessage('tnow value is ' + tnow);
if (gs.dateDiff(current.start_date.getDisplayValue(), tnow , true) <= 0)
return;
gs.addErrorMessage(gs.getMessage("{0} must be after current time", [ current.start_date.getLabel()]));
current.setAbortAction(true);
}
regards
Rajesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2019 01:16 PM
That is basically what I'm dong except I'm not calling a function. But when I click on the UI Action I get no message and nothing else happens even if I'm at or after the start time. Here is the full code from the UI Action. This is mostly the OOB UI Action.
function moveToImplement(){
var tnow = gs.nowDateTime();
if (gs.dateDiff(current.start_date.getDisplayValue(), tnow , true) <= 0){
gs.addErrorMessage('You cannot implement this change before the approved change windows. ' + current.start_date.getDisplayValue());
current.setAbortAction(true);
}
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-10-2019 01:25 PM
put a addinfo message on line 2 and see if you getting any value for tnow and please do check if condition to run is ok
var tnow = gs.nowDateTime();
Also i can see that you are not using "return"
you are asking the system to return the message

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2019 01:43 PM
I'm not getting the add info message and when I tried to add the return where you had it I got errors on the reset of the script. I have never had to add a return to display a message using a business rule.