How to make worknotes mandatory using UI actions.

divyal09
Tera Contributor

I want to add a code to the below code to make the worknotes mandatory whenever user clicks on re-evaluate it should show pop up like please enter worknotes.

var approvals = new GlideRecord('sysapproval_approver');
approvals.addQuery('sysapproval.number', current.number);
approvals.addQuery('state', 'requested');
approvals.setLimit(1);
approvals.query();

while (approvals.next()) {

approvals.setValue('state', 'rejected');
approvals['comments'].setJournalEntry("Rejected by " + gs.getUserDisplayName() + " for re-evaluation");
approvals.update();

}

2 REPLIES 2

Danish Bhairag2
Tera Sage
Tera Sage

Hi @divyal09 ,

 

If u want to make work notes mandatory using UI action then u need to make certain modifications in your existing code.

  1. Click the checkbox for client as true on the UI action. You Ui action will behave like client script instead of Server Side & will accept all client side commands.
  2. U need to move the above code in script include which should be client callable.
  3. Call that script include using GlideAjax in your UI action.
  4. You can use below line whenever u want to make work notes mandatory.
g_form.setMandatory('work_notes',true);

 

Thanks,

Danish

 

Akshay Gupta2
Kilo Sage

Hi @divyal09 

 

To achieve this functionality You can create one Client Script of type - onSubmit. In script you can check if worknote is empty then show message.

function onSubmit() {
   //Type appropriate comment here, and begin script below
        var workNotesValue = g_form.getValue('work_notes');
     if (workNotesValue == "" && !workNotesValue) {

            alert('Worknote is mandatory.');
            g_form.clearMessages();
            g_form.showFieldMsg('work_notes', 'Worknote is mandatory.', 'error');
        
    }  
}

  

Regards,

Akshay