How to make comments mandatory in Employee Center Portal

vidhya_mouli
Giga Sage

This is our Employee Center Portal:

 

vidhya_mouli_0-1701182664147.png

 

When the caller decides to resolve the incident, a comment field should be mandatory. I am using a BR for this purpose.

(function executeRule(current, previous /*null when async*/) {

	var callerName = current.caller_id.getDisplayValue();
	var assignedTo = current.assigned_to.getDisplayValue();
	var comments = current.comments;
	
	gs.addInfoMessage("COMMENTS: " + comments);
		  
	// Get the autoclose time period
    var autoCloseTime = gs.getProperty('glide.ui.autoclose.time');
	
    // Build the message with placeholders
	if (current.caller_id == current.resolved_by) {
		current.setMandatory('assigned_to', false);

		if (!comments) {
                // Display a message to prompt the caller to enter a comment
                gs.addErrorMessage("Please enter a comment before resolving the incident.");
                current.setAbortAction(true); // Set the state back to its previous value
        } else {
			var workNotesMessage = "Hi " + assignedTo + "," + "\n\n" +
            "This Incident is resolved and doesn't require further attention.\n";
		}
    } else {
		var workNotesMessage = "Hi " + callerName + "," + "\n\n" +
            "Your incident has been resolved.\n\n" +
            "Summary details:\n" +
            "Resolved by: " + gs.getUserDisplayName() + "\n" +
            "Resolution code: " + current.close_code + "\n" +
			"Resolved notes: \n" + current.close_notes.getDisplayValue() + "\n\n" +
            "The incident will automatically close in " + autoCloseTime + " days" + "\n\n" +
            "You can either reopen or close the incident using the Actions button.";

		// Set the updated work_notes field
		if(!assignedTo) {
			gs.addErrorMessage("Assigned to field is mandatory");
			current.setAbortAction(true);
		} else {
    		current.comments = workNotesMessage;
		}

	}

})(current, previous);


However, it is unable to capture the comment filed. How do I do this?

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @vidhya_mouli 

 

May be helpful

 

https://www.servicenow.com/community/developer-forum/make-rejection-comment-mandatory-in-service-por...

 

https://www.servicenow.com/community/developer-blog/portal-diaries-service-portal-making-rejection-c....

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

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

So editing the widget is the only way and this cannot be done through a business rule?

Yes @vidhya_mouli 

 

Due to Portal the best way yo edit widget, but first make a copy of widget and then make changes.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

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

Thank you.