Make comments mandatory when incident state changes resolve to reopened in service portal

Srilatha Vadlam
Tera Contributor

Make comments mandatory when incident state changes resolve to reopened in service portal.
here I am adding a image.

SrilathaVadlam_1-1750919677163.png

 

Here there is a action button we can open incident state to reopen here. 

SrilathaVadlam_2-1750919726592.png

Please suggest your solution.

 

8 REPLIES 8

nityabans27
Mega Guru

To make comments mandatory when Incident state changes from "Resolved" to "Reopened" in Service Portal, use a UI Policy + Client Script combo:


Solution

1. UI Policy on incident table

  • Condition: State changes from Resolved to In Progress (or appropriate "Reopened" state)

  • Set Additional Comments → Mandatory

2. Client Script (type: onSubmit, UI Type: All)

function onSubmit() {
  if (g_form.getValue('state') == '2' && g_form.getValue('state').changedFrom('6')) {
    if (!g_form.getValue('comments')) {
      g_form.showFieldMsg('comments', 'Comments are required when reopening', 'error');
      return false;
    }
  }
  return true;
}

Replace 2 = In Progress, 6 = Resolved as per your instance state values.

 

SrilathaVadlam_0-1750924848470.png

Changes is not available in UI Policy.
Could you please help me on this

Srilatha Vadlam
Tera Contributor

Hi Nitya,

I tried it is not working, could you please help me any other way

 

To make comments mandatory when an Incident is reopened (Resolved → In Progress) in Service Portal, you need to work around how the Service Portal doesn't always handle onSubmit scripts reliably — especially when it comes to changedFrom() logic.


Approach That Works in Service Portal

1. Create a hidden field

  • Add a new hidden field to the incident table. Call it something like state_changed_from_resolved (type: true/false).

  • Set default value: false.


2. Business Rule (Server-side)

  • Create a before Business Rule on the Incident table:

if (current.state == 2 && previous.state == 6) { // 2 = In Progress, 6 = Resolved
   current.state_changed_from_resolved = true;
} else {
   current.state_changed_from_resolved = false;
}

This marks the record when transitioning specifically from "Resolved" → "In Progress".


3. UI Policy

  • Table: incident

  • Condition: state_changed_from_resolved is true

  • Action: Make comments field mandatory

Note: In Service Portal, comments refers to "Additional Comments", not "Work Notes".


4. Client Script (optional validation backup)

  • Type: onChange, Field: state

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue != '2' || oldValue != '6') return;

  g_form.setValue('state_changed_from_resolved', true);
  // This ensures the UI policy kicks in real-time
}

⚠ Why previous Didn’t Work

  • changedFrom() doesn't work client-side in Service Portal.

  • g_form.getValue('state').changedFrom('6') is invalid JS — getValue() returns a string, not an object.

  • SP does not enforce onSubmit the same way classic UI does.