
- 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 01:55 PM
hope the condition to run the ui action is right

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2019 01:55 PM
I just restored it back to the OOB version then add in just var tnow = gs.nowDateTime(); and it stops working. it does not seem to like this code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2019 02:05 PM
Lets debug this .
trying running this on script backgroud on any change and try to see if you can print the message
var sysid = 'sysid of change'
var tnow = gs.nowDateTime();
do glide on change
if next()
{
if (gs.dateDiff(gr.start_date.getDisplayValue(), tnow , true) <= 0)
return;
print('error');
else
{
print ('no error');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 05:17 AM
It work after removing the return. The return gives an error when you try to run in the script background. You cannot do a return and have the reset of the script run. And fixed some other stuff with the script like missing semicolons and squiggly brackets.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 05:26 AM
My bad return will always return error when you running it on scripts background.
So first part of the code is work
hope moveToImplement() is added to Onclick field on UI action