How to add a new form field mandatory during Suspend Dialog Box save?

manish123
Giga Guru

Hi All,

In HR form, we are using Suspend UI action and OOB we are getting Reason & Work Notes field in the dialog box. Now, we would like to make Due Date field as mandatory in the form when Suspend Reason dialog box change gets saved?

I think making a field mandatory when the control is in dialog box would be quite tricky. However, I think I should include Due Date too in the Suspend Dialog Box and make it mandatory and after filling the value should be displayed in the Due Date field in the form.

Could anyone of you please help or guide me to achieve this?

Quick reply would be much appreciated.

 

 

 

4 REPLIES 4

Kalyani Jangam1
Mega Sage
Mega Sage

Hi Manish

Please make following changes in UI page, Script include and client script that related with suspend UI action

***********************************************************************************************

UI Page=>HR Suspend Dialog=>sn_hr_core_HR Suspend Dialog

In HTML add below line for add due date

<div class="form-group is-required row">
                <label for="suspend_due_date" class="control-label col-sm-3" style="text-align:right">
                    <span class="required-marker"></span>${gs.getMessage('Due Date')}
                </label>
                <span class="col-sm-9">
                    <input id="suspend_due_date" class="col-sm-9 form-control" required="required" rows="3" type="date" data-date="" data-date-format="DD MMMM YYYY" aria-required="true" placeholder="${gs.getMessage('Due Date')}" name="suspend_due_date" />
                </span>
            </div>

In Processing script

var hrCase = new GlideRecord('sn_hr_core_case');
        hrCase.get(order_sys_id);
        hrCase.sla_suspended_reason = suspend_reason;
        hrCase.work_notes = suspend_comments;
        hrCase.due_date=suspend_due_date;// add this line to set due date value
        hrCase.sla_suspended = true;
        hrCase.state = 24;
        hrCase.sla_suspended_on = new GlideDateTime().getDisplayValue();
        hrCase.update();

*****************************************************************************************************

Client script=>Suspend Dialog Box

    //Call the Ajax function that handles adding worknotes and state
                var s = new GlideAjax("sn_hr_core.hr_CaseAjax");
                s.addParam("sysparm_name", "suspendCaseAction");
                s.addParam("sysparm_obj_id", sysId);
                s.addParam("sysparm_table_name", tblName);
                s.addParam("sysparm_work_note", newWorkNote);
                s.addParam("sysparm_suspend_reason", newReason);
                s.addParam("sysparm_suspend_due_date",newDueDate);// add this parameter to send due date value 
                s.getXML(addWorkNotes);

******************************************************************************************************

Script include=>hr_CaseAjax

In below function, add below bold line

    suspendCaseAction: function () {
        var objSysId = this.getParameter('sysparm_obj_id');
        var tblName = this.getParameter('sysparm_table_name');
        var newWorkNote = this.getParameter('sysparm_work_note');
        var newReason = this.getParameter('sysparm_suspend_reason');
        var newDueDate=this.getParamter('sysparm_suspend_due_date');// return parameter of due date

        var hrCase = new GlideRecord(tblName);
        hrCase.get(objSysId);
        if (!hrCase.isValid() || !hrCase.canWrite())
            return null;
        
        this._setSuspensionReason(hrCase, newReason);
        this._updateNotes(hrCase, newWorkNote, false);
        hrCase.due_date=newDueDate;// to set Due Date Value
        hrCase.state = hr.STATE_SUSPENDED;
        hrCase.update();
        return hrCase;
    },

*****************************************************************************************************

Please try this code, I have already use, it will work

Mark Helpful if it will work and let us know your comment

Hi Kalyani,

Thanks for your response.

Much appreciated.

However, I would like to make Due Date mandatory in the Dialog box once Suspended Reason is selected as a specific value and not to be always.

 

UI Page=>HR Suspend Dialog

add below line in HTML

label.required::before {
  content: '*';
  color: red;
}
label.notrequired::before {
  content: '*';
  color: grey;
}

    <select id="suspend_reason" class="form-control" name="suspend_reason" onchange="checkMandatory()"> // for suspended reason choices

 

<div class="form-group is-required row">
                <label for="suspend_due_date" id="suspend_date" class="control-label col-sm-3" style="text-align:right">
                    ${gs.getMessage('Due Date')}
                </label>
                <span class="col-sm-9">
                    <input id="suspend_due_date" class="col-sm-9 form-control" rows="3" type="date" data-date="" data-date-format="DD MMMM YYYY"  placeholder="${gs.getMessage('Due Date')}" name="suspend_due_date"  />
                </span>
            </div>

--------------------------------------------------------------------------------------

Client script

function checkMandatory() {
    alert("1111 function calls");
    var x = document.getElementById("suspend_reason").value;
    alert("x---------" + x);
    if (x == 'company') { // If is company then only mandatory
        alert("In Ifff loop--");
        document.getElementById('suspend_date').setAttribute("class", "required"); // when empty
        
    }
    else{
        document.getElementById('suspend_date').setAttribute("class", "notrequired"); // when empty
    }
    
}

Please Mark Helpful and Answer Correct if it helpful

hi do you have any option for workspace, to the Suspend Dialog Box client script?

Wish to achieve:

if reason is "user" the work note field is mandatory