How to configure the Inactivity notification for problem record

Research
Tera Guru

How to configure the Inactivity notification for problem record

I have created Inactivity event
and Notification on problem 
under who will receive - Assignment group of problem is working expected

Research_0-1744573589740.png

 



also want to send the same notification to the associated problem task analysts field "assigned to"

please guide me the steps 

Thanks,

3 REPLIES 3

Blaze Llanos
Kilo Expert

1. Create a Script on the Problem Table
Navigate to System Definition > Business Rules > Scripts - Background
Create a new Script with the following settings:
Name: Send Problem Inactivity to Task Assigned To 
Table: Problem [problem]
Run this script: After (Update)
Condition:
State | changes to | Inactivity Monitor [Your Inactivity Monitor choice] (This ensures the script runs when the Problem enters the inactivity state)
Script:

(function runScript(/* GlideRecord */ current, /* GlideRecord */ event, /* EmailClient */ emailClient, /* GlideSystem */ gs) {

    try {
        if (current.state.changesTo('YOUR_INACTIVITY_MONITOR_STATE')) { // Directly check if transitioning to inactivity
           
            // Efficiently query for assigned_to of related Problem Tasks
            var taskGr = new GlideRecord('problem_task');
            taskGr.addQuery('problem', current.sys_id);
            taskGr.query();

            while (taskGr.next()) {
                var assignedTo = taskGr.assigned_to.toString();
                if (assignedTo) { // Make sure there's an assigned_to user
                    // Instantiate and personalize the notification
                    var notification = new GlideNotification('YOUR_NOTIFICATION_SYS_ID');
                    notification.addRecipient('user', assignedTo);
                    notification.setWorkFlow(current);
                    notification.autoResponse(false);
                    notification.send();
                }
            }
        }
    } catch (ex) {
        gs.error("Error in Send Problem Inactivity to Task Assigned To script: " + ex);
        // Additional error handling if needed, e.g., sending an email alert
    }

})(current, event, emailClient, gs);

Research
Tera Guru

Hi @Blaze Llanos 
Thanks for response 
we dont have problemstate to choose inactivity
Can you guide me with email scripts


reference Like this

Solved: Email Script - Add users to CC field - ServiceNow Community
Thanks

blaze1
Tera Contributor

Adding Problem Task Assignees to the Email Body

Go to:
System Notification > Email > Notifications

Open your Problem Inactivity Notification

In the Message HTML section, insert this Email Script or call a new one.

Create an Email Script:

Name: List Problem Task Assignees

Applies to: Problem

Script:

// Fetch related problem tasks

var taskGr = new GlideRecord('problem_task');

taskGr.addQuery('problem', current.sys_id);

taskGr.query();

 

var taskAssignees = [];

while (taskGr.next()) {

    if (taskGr.assigned_to) {

        taskAssignees.push(taskGr.assigned_to.getDisplayValue());

    }

}

 

if (taskAssignees.length > 0) {

    template.print("<p><strong>Assigned Analysts on Problem Tasks:</strong></p><ul>");

    for (var i = 0; i < taskAssignees.length; i++) {

        template.print("<li>" + taskAssignees[i] + "</li>");

    }

    template.print("</ul>");

} else {

    template.print("<p><strong>No analysts assigned to problem tasks.</strong></p>");

}


Optionally Adding Them as CC Recipients

If you also want to actually send the notification to those users (not just show in the email), you could:

Modify the Notification > Who will receive section
Add a Scripted Recipient

Scripted Recipients example:

var recipients = [];

var taskGr = new GlideRecord('problem_task');

taskGr.addQuery('problem', current.sys_id);

taskGr.query();

 

while (taskGr.next()) {

    if (taskGr.assigned_to) {

        recipients.push(taskGr.assigned_to.toString());

    }

}

recipients;



Email Script → to dynamically show Problem Task assignees inside the email body.

Scripted Recipient (optional) → to actually CC/notify those users.

Blaze Llanos, USMC, MISM
ServiceNow Engineer
Solutions: IT | ServiceNow Expertise Transforming Challenges into Solutions
LinkedIn: https://www.linkedin.com/in/blazellanos/