We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to make comments mandatory in Employee Center Portal

vidhya_mouli
Tera 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

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....

 

*************************************************************************************************************
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

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

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.

*************************************************************************************************************
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

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

Thank you.