Scenario Based Question - ITSM

priyayadav8
Tera Contributor

Whenever an Incident's priority changes to P1, you want to notify the user and make attachments mandatory .How to achieve this?

1 ACCEPTED SOLUTION

Sarthak Kashyap
Mega Sage

Hi @priyayadav8 ,

 

I tried your problem in my PDI and it works for me please create OnBefore Business Rule on your Incident table, and add below script

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

    // Add your code here
    gs.log("Inside BR");
    if (current.priority == 1 || current.priority == "1") {
        if (current.hasAttachments() != true) {
            gs.log("Inside BR IF");
            gs.addErrorMessage("Please add an attachment");
            current.setAbortAction(true);
        }
    }


    gs.eventQueue('Event_Name', current, current.caller_id, current.assigned_to);

})(current, previous);

SarthakKashyap_0-1763290346968.png

 

SarthakKashyap_1-1763290347987.png

 

 

You can create a event from event Registry and create a Notification, trigger that notification when event is fired, and in who will receive section check the checkbox of recipient contains parm1 &parm2. Add your subject and body accordingly.

SarthakKashyap_2-1763290346971.png

 

SarthakKashyap_3-1763290346970.png

 

 

 

Result

SarthakKashyap_4-1763290346968.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

View solution in original post

5 REPLIES 5

Sarthak Kashyap
Mega Sage

Hi @priyayadav8 ,

 

I tried your problem in my PDI and it works for me please create OnBefore Business Rule on your Incident table, and add below script

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

    // Add your code here
    gs.log("Inside BR");
    if (current.priority == 1 || current.priority == "1") {
        if (current.hasAttachments() != true) {
            gs.log("Inside BR IF");
            gs.addErrorMessage("Please add an attachment");
            current.setAbortAction(true);
        }
    }


    gs.eventQueue('Event_Name', current, current.caller_id, current.assigned_to);

})(current, previous);

SarthakKashyap_0-1763290346968.png

 

SarthakKashyap_1-1763290347987.png

 

 

You can create a event from event Registry and create a Notification, trigger that notification when event is fired, and in who will receive section check the checkbox of recipient contains parm1 &parm2. Add your subject and body accordingly.

SarthakKashyap_2-1763290346971.png

 

SarthakKashyap_3-1763290346970.png

 

 

 

Result

SarthakKashyap_4-1763290346968.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Hi Sarthak,
 Thanks it's working ,without event also we can achieve this.

MaxMixali
Mega Sage

 

Hi you can create a new Notification

  1. Navigate to: System Notification > Email > Notifications
  2. Click New
  3. Configure:
 
 
Notification Configuration:- Name: P1 Incident - Notify User and Require Attachments- Table: Incident [incident]- Active: ✓- Send when: Update
When to send tab:Conditions:- Priority changes to 1 - Critical
Who will receive tab:- Users/Groups in fields: Caller
What it will contain tab:Subject:Your Incident ${number} Has Been Escalated to P1 - Critical
Message HTML:<p>Hello ${caller_id.name},</p>
<p>Your incident <strong>${number}</strong> has been escalated to <strong>Priority 1 (Critical)</strong>.</p>
<p><strong>Incident Details:</strong></p><ul>    <li><strong>Short Description:</strong> ${short_description}</li>    <li><strong>State:</strong> ${state}</li>    <li><strong>Assigned to:</strong> ${assigned_to}</li>    <li><strong>Created:</strong> ${sys_created_on}</li></ul>
<p style="color: red;"><strong>IMPORTANT:</strong> Attachments are <u>mandatory</u> for P1 incidents. Please ensure you have attached all relevant files (screenshots, logs, error messages, etc.).</p>
<p><a href="${mail_script:incident_link}">View Incident</a></p>
<p>If you have questions, please contact the IT Service Desk.</p>
<p>Thank you,<br>IT Service Desk</p>

sniks2122
Tera Contributor

Hi Priya,

We can achive this using client script as well,but /

Why Client Script is NOT a useful solution for mandatory attachments

Client Scripts run only in the browser/UI, so they work only when a user is manually updating the record from the form.
They do not run for:

  1. REST API updates
  2. Integration updates
  3. Flow Designer / Workflow updates
  4. Import Set / Transform Map updates
  5. Background scripts
  6. Other Business Rules or Scripted updates

This means if Priority becomes P1 through any non-UI method, the Client Script will never trigger, and the incident can still become P1 without any attachment, which breaks the requirement.

Business Rule = server-side → mandatory for all update paths

Before Update BR:

if (current.priority == 1 && previous.priority != 1) {

    if (!current.hasAttachments()) {
        gs.addErrorMessage("Attachments are mandatory when priority becomes P1.");
        current.setAbortAction(true);  // Stop the update
    }

}