Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Add UI action to add watch list on sysapproval_approver table

suvarna sonar2
Tera Contributor

user should be able to add user email in watch list through ui action

4 REPLIES 4

GlideFather
Tera Patron

Hi @suvarna sonar2,

 

What user should be able to do so? Because if the user doesn't have itil they will not have access to backend and thus neither to UI Actions there...

 

This seems a little strange to me... can you please explain the business justification behind this requirement? 

 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


suvarna sonar2
Tera Contributor

user want to add user in watch list , we have watcht list collector field on approval table but that filed is not editable even for admin. This OOB behaviour.

Can you @suvarna sonar2 please share any screenshot or context?

 

What you describe doesn't sound much like OOTB... and also how do you define "user"?

 

I checked for both CHG and KB approvals but there's no watch list available OOTB:

GlideFather_0-1763656128909.png

 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


MaxMixali
Kilo Sage

Option 1: Add Current User's Email to Watch List

UI Action Configuration:

  • Name: Add to Watch List
  • Table: incident (or your table)
  • Action name: add_to_watchlist
  • Form button: true
  • Show insert: false
  • Show update: true
  • Client: false (server-side)

Script:

 
 
javascript
(function addToWatchList() {
    
    // Get current user's email
    var userEmail = gs.getUserID();
    var user = new GlideRecord('sys_user');
    if (user.get(userEmail)) {
        var email = user.email.toString();
        
        // Get current watch list
        var watchList = current.watch_list.toString();
        
        // Check if email already exists
        if (watchList.indexOf(email) === -1) {
            // Add email to watch list
            if (watchList) {
                current.watch_list = watchList + ',' + email;
            } else {
                current.watch_list = email;
            }
            current.update();
            gs.addInfoMessage('You have been added to the watch list');
        } else {
            gs.addInfoMessage('You are already in the watch list');
        }
    }
    
    action.setRedirectURL(current);
    
})();





Hello i hope that can help

If you find this answer useful, please mark it as solution accepted/helpful

Massimiliano Micali