
- 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 06:32 AM
no , i am saying to put inside the script field where you have already mentioned the if block.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 06:34 AM
also add log and see what are you getting in logs .
gs.log('Date Diff ' + gs.dateDiff(current.start_date.getDisplayValue(), tnow.getDisplayValue() , true));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 06:36 AM
if i see your moveToImplement() you have added client side code, and dateDiff() is server side code , which will not work. use that in server side function block.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 06:40 AM
the client checkbox is checked for your UI Action, correct?
then it is my understanding that "gs is a server side object, it cannot be used in client scripts."

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2019 07:00 AM
There should be sections where you can run server side script. This UI Action also has current.update and action.setRedirectURL which is server side. I can run my code it there the problem is that a g_form.setValue has already run.