Popup the message according to the freeze period dates in change request

akila reddy
Tera Contributor

Hi all, I have a requirement on the change request. There are couple of freeze period dates and if the change request is raised with the type as Normal or emergency or urgent, the planned date and end dates are given with in the freeze period then a popup message should come up like " you are attempting to implement this change in freeze period. Please provide justification in the business justification field." Can anyone please help me with this. Thanks in advance.

2 REPLIES 2

Akash4
Kilo Sage
Kilo Sage

Hi Akila,

You can achieve this using Client Script as follows:

function onSubmit() {
var plannedDate = g_form.getValue('planned_start_date');
var endDate = g_form.getValue('planned_end_date');
var changeType = g_form.getValue('change_type');

 

var freezeStartDate = new Date('YYYY-MM-DD'); // Start of freeze period
var freezeEndDate = new Date('YYYY-MM-DD'); // End of freeze period

var plannedStart = new Date(plannedDate);
var plannedEnd = new Date(endDate);

if (changeType === 'Normal' || changeType === 'Emergency' || changeType === 'Urgent') {
if ((plannedStart >= freezeStartDate && plannedStart <= freezeEndDate) ||
(plannedEnd >= freezeStartDate && plannedEnd <= freezeEndDate) ||
(plannedStart <= freezeStartDate && plannedEnd >= freezeEndDate)) {
alert("You are attempting to implement this change in freeze period. Please provide justification in the business justification field.");
g_form.setFocus('business_justification'); // Adjust field name as necessary
return false;
}
}

return true;
}

 

 

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Hi Akash,

Thanks for your response. But it is not working. i have around 10 freeze period dates. I have used a script include and client script to acheive this. Not sure where it was wrong.

 

Script include : 

 

var FreezePeriodCheck = Class.create();
FreezePeriodCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    isDateInFreezePeriod: function() {
        var startDate = this.getParameter('sysparm_start_date');
        var endDate = this.getParameter('sysparm_end_date');
       
       
        var freezeGR = new GlideRecord('cmn_schedule_span');  
        freezeGR.addQuery('start_date', '<=', endDate);
        freezeGR.addQuery('end_date', '>=', startDate);
        freezeGR.query();

        if (freezeGR.hasNext()) {
            return 'true';  
        }
       
        return 'false';  
    }
});
 
Client script : 
 
function onSubmit() {
   (function executeSubmitScript(control, oldValue, newValue, isLoading, isTemplate) {
   
    if (isLoading || newValue === '') {
        return;
    }

    var changeType = g_form.getValue('type');
    var plannedStartDate = g_form.getValue('start_date');
    var plannedEndDate = g_form.getValue('end_date');

    var validChangeTypes = ['normal', 'emergency', 'urgent'];

   
    if (validChangeTypes.indexOf(changeType) !== -1) {
       
        var ga = new GlideAjax('FreezePeriodCheck');  
        ga.addParam('sysparm_name', 'isDateInFreezePeriod');
        ga.addParam('sysparm_start_date', plannedStartDate);
        ga.addParam('sysparm_end_date', plannedEndDate);
        ga.getXMLAnswer(function(answer) {
            if (answer === 'true') {
               
                alert("You are attempting to implement this change during a freeze period. Please provide justification in the Business Justification field on why this change must be implemented on this date.");
               
               
               
            }
        });
    }
   
    return true;
})(g_form, g_form.getValue('type'));
}