UI Action Display Error message

Brian Lancaster
Tera Sage

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?

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

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);
}

View solution in original post

26 REPLIES 26

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()

find_real_file.png

nope same outcome.  When I click on it nothing happens.

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);
}

Anurag Tripathi
Mega Patron
Mega Patron

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

-Anurag

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.