
- 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 05:35 AM
OK try this
function checkDate()
{
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
{
moveToImplement()
}
}
function moveToImplement(){
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);
}
and note replace Onclick to checkDate()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 05:50 AM
nope same outcome. When I click on it nothing happens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 06:48 AM
ok
i just tested this and this work for me
need to make some changes in the UI action
uncheck client and add this to the script and let me know
checkDate();
function checkDate()
{
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 {
moveToImplement();
}
}
function moveToImplement(){
gs.addInfoMessage('hello');
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 05:30 AM
Hi Bryan,
Not read the complete thread, so apologies if this was already discussed.
But i feel the ui action should not be available if it cannot be used at a particular time/stage. So I would add it in the condition to now show the ui action until it can be used. Often i have seen state and sub state being used for this, for eg...state is ready to be implemented but sub state is pending(waiting for window start) and when sub state changes to ready, that is when it can be processed.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 05:42 AM
I tried that but I could not figure out how to write the condition. Scripting with Date/Times is something I always have problems with.