Notification on custom table

Nisha B
Tera Expert

Hello All,

I want to set up notification on custom table which have the RITM number , Change request and Change task , Requested for this all are string field , so when the record in custom table status mark as failed , i need to trigger a mail to Requested For , Now here requested for is a string field which holds the user id .

I am not getting how to bring this requested for in CC as this is a string filed we need to populate the email with respect to User ID present in Requested For field and this requested for should come like Dear ${Requester}

 

Please help on this.

 

Thanks 

7 REPLIES 7

Community Alums
Not applicable

Hi @Nisha B ,

You will need to dot walk : 

SandeepDutta_1-1689935766224.png

 

SandeepDutta_0-1689935744523.png

 

Hello Sandeep,

 

this notification is on custom table which have string field this field are not reference field Requested For is string field which have user Id .So how to use that in adding the address

Riya Verma
Kilo Sage
Kilo Sage

Hi @Nisha B ,

 

Hope you are doing great.

To set up notifications on a custom table in ServiceNow for IT asset management, follow these steps:

  1.  Create a new Business Rule that triggers when the record status on the custom table is marked as "failed."

 

// Business Rule Name: NotifyOnStatusFailed
// Table: <your_custom_table>
// When: Before
// Insert true
// Update true

(function executeRule(current, previous /*, g*/) {
    if (current.status == 'failed') {
        var requestedFor = current.requested_for; // Assuming "requested_for" is the field holding the User ID

        if (requestedFor) {
            // Get the user's email using the user ID from the "requested_for" field
            var user = new GlideRecord('sys_user');
            if (user.get('user_name', requestedFor)) {
                var email = user.email;
                if (email) {
                    // Send the email notification
                    var subject = 'Notification: Record Status Failed';
                    var body = 'Dear ' + requestedFor + ',\n\nThe status of your record on the custom table has been marked as failed.';
                    gs.eventQueue('email.send', current, email, '', subject, body);
                }
            }
        }
    }
})(current, previous);

 

send the notification - who will receive or set it via notification email script.

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Namrata Ghorpad
Mega Sage
Mega Sage

Hi @Nisha B 

Create Email Script for the notification and in that email script write code like below and try.

var requestedFor=current.u_requested_for; 
var grUser=new GlideRecord('sys_user');
grUser.addQuery('name',requestedFor);//if sysid is in Requestedfor field then use grUser.addQuery('sys_id',requestedFor);
grUser.query();
if(grUser.next())
{
email.addAddress("cc",grUser.email,grUser.name);
}

 

Please refer the below link.

https://www.servicenow.com/community/now-platform-forum/how-to-set-cc-with-email-content/m-p/1025103 

 

Please mark my answer as helpful and correct if it helps you.

Regards,

Namrata