Is it possible to make Comments mandatory on incident form of service portal while reopening the inc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there,
I have a requirement to make comments mandatory if end user tries to reopen the incident by using "Reopen" ui action on service portal.
Is it feasible to achieve? if yes the how? if not, could you please share any servicenow document stating the same?
Thank!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
The OOB UI action "Reopen Incident" does that.
Post the definition of your "Reopen" UI Action (or whatever you have that processes that button.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SandeshB ,
Yes, it is feasible to make the Comments (or Additional Comments) field mandatory when an end user tries to Reopen an incident from the Service Portal using custom solution. I’ve done something similar before; here’s what works, sample approach and things to watch out for. You can tweak for your setup....
>> Add a hidden boolean field on the incident table (e.g. u_was_resolved) to track whether the incident was in Resolved state before being reopened.....
>> Create a Before Update Business Rule:
If current.state (or incident_state) is being changed to Reopened (or whatever state you use) AND the previous state was Resolved, set the u_was_resolved field to true. Else, false....
>>On the form used in the Service Portal, create a UI Policy (or modify the relevant widget / form) with condition: u_was_resolved == true. In that UI Policy, set Comments (or Additional Comments) field mandatory.....
>>Add a Client Script (onSubmit) for that form / portal widget:
If state = Reopened and u_was_resolved is true, check if Comments is not empty. If empty, show error message (e.g. Comments are required when reopening the incident) and prevent submit....
>>Add server-side validation as well (another Business Rule or in the UI Action / workflow chain) so that even if client logic is bypassed, the record cannot be reopened without comments.....
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I believe you can do this by adding a condition in UI action script. Can you share your script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
This is from the OOB UI Action named "Reopen" defined on the incident table:
// Client side onclick function
function reopenIncident() {
if (g_form.getValue('comments') == '') {
g_form.setMandatory('comments', true);
}
gsftSubmit(null, g_form.getFormElement(), 'reopen_incident'); // MUST call the 'Action name' set in this UI Action
}
// Code that runs without 'onclick'
// Ensure call to server side function with no browser errors
if (typeof window == 'undefined')
serverReopen();
function serverReopen() {
// Set Incident state to active, update and reload the record
current.incident_state = 2;
current.state = 2;
current.update();
var msg;
if (current.child_incidents > 0) {
msg = gs.getMessage("{0} and its child incident(s) have been reopened", current.getDisplayValue());
} else {
msg = gs.getMessage("{0} has been reopened", current.getDisplayValue());
}
gs.addInfoMessage(msg);
action.setRedirectURL(current);
}