Popup not triggering when condition is met

Aaron Duncan
Mega Sage

I have a requirement where the popup is to be triggered if a user attempts to implement a change before the planned start date/time, otherwise it continues as normal. 

I'm passing the current date/time into a script include to process, and return a true or false. If the answer is true, then the popup is supposed to trigger.

 

Here's the UI Action code

//Client-side 'onclick' function
function moveToImplement() {
    // Create AJAX call to determine if start date value is smaller than now. If it is, then proceed. Otherwise, create popup.
    var startDate = g_form.getValue("start_date");
    var ga = new GlideAjax("DateUtil"); // Script Include to call.
    ga.addParam("sysparm_name", "hasDatePassed"); //Function in the Script Include to call.
    ga.addParam("sysparm_date", startDate); //passing the startDate into the function.
    ga.getXMLAnswer(_isItPassed); //Callback function to return the result when ready.
	//ga.getXMLWait(_isItPassed);


    //Call the UI Action and skip the 'onlick' function
    // gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
    // if (typeof window == "undefined") setRedirect();

    function setRedirect() {
        current.update();
        action.setRedirectURL(current);
    }

    function _isItPassed(response) {
        var answer = response;
		//var answer = response.responseXML.documentElement.getAttribute('answer');
        if (answer === "true") { //if the answer is true, the start date/time is passed and can move to implement.
            g_form.setValue("state", "-1");
			g_form.save();
            gsftSubmit(null, g_form.getFormElement(), "state_model_move_to_implement");
			if (typeof window == "undefined") setRedirect();

        } else {
            renderForm(); //If false, then it creates the popup. once the popup is complete, then it will move along in the process.
        }
    }

    function renderForm() {
        var tableName = g_form.getTableName();
        var dialog = new GlideDialogWindow("change_start_early");
        dialog.setTitle("Reason why Change is going early.");
        dialog.setPreference("target_table", tableName);
        dialog.render();
    }
}

 

Here is the Script Include used to process the times.

var DateUtil = Class.create();
DateUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    // initialize: function() {},
    // Usage: new DateUtil().hasDatePassed(current.getValue('state_date'))
    //
    hasDatePassed: function() {
        var dateFieldValue = this.getParameter("sysparm_date");
        var now = new GlideDateTime();
        var plannedDate = new GlideDateTime(dateFieldValue);

        if (plannedDate.getNumericValue() < now.getNumericValue()) {
			return true;
        } else {
			return false;
        }
    },
    type: 'DateUtil'
});

 

Can someone help me point out what is preventing the popup from triggering?

0 REPLIES 0