- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 03:48 AM
Hello I want to send an email to some person based on some logic of my app. I would like to do this from ServiceNow-> Script Include. How to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 09:56 AM - edited 06-01-2023 01:15 AM
Hello Thank you for your response
I will tell what I have done.
1. I created an Event Registry simply.
2. I created a Notfication
3. I created a Script Include and there I used
gs.eventQueue('x_8041114_needlt.EmailEvent1',current,'abc@gmail.com','axyz@gmail.com');
Update
Now I am able to send the email but I have to use the glideobject as 2nd parameter. But I do not want to use that. I do not want to use glideobject because my business logic doesn't need it. I want to use eventQueue() in a way that I pass the event name that will be fired, and some normal parameters but no glideobject. How should I write eventQueue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 04:17 AM
Hi,
May this will work,
There are two ways to send an email from ServiceNow:
- From a record
To send an email from a record, follow these steps:
Go to the record that you want to send the email from.
Click the More Options button and select Email.
In the Email window, enter the email addresses of the recipients in the To field.
Enter the subject of the email in the Subject field.
Enter the body of the email in the Body field.
Click the Send button to send the email.
From the ServiceNow console
To send an email from the ServiceNow console, follow these steps:
- Click the Email button in the ServiceNow console.
- In the Email window, enter the email addresses of the recipients in the To field.
- Enter the subject of the email in the Subject field.
- Enter the body of the email in the Body field.
- Click the Send button to send the email.
Prerequisites
Before you can send an email from a ServiceNow instance, you must ensure that the following prerequisites are met:
- The Enable email sending (SMTP) system property is set to Yes.
- The SMTP server settings are configured correctly.
- The user account that you are using has the Send Email permission.
Troubleshooting
If you are having problems sending emails from a ServiceNow instance, you can try the following troubleshooting steps:
- Verify that the Enable email sending (SMTP) system property is set to Yes.
- Verify that the SMTP server settings are configured correctly.
- Verify that the user account that you are using has the Send Email permission.
- If you are still having problems, contact your ServiceNow administrator for assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 04:23 AM
Hello @dev115415 ,
You can create a record in the event registry.
Create notification and in when to send select when event is fired and select the event name.
Then in script include call the event (use, gs.addEventQueue() function).
If this solves your query, mark this as correct and helpful.
Regards
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 05:21 AM
Hello, I have done the first 2 steps. Now how to specify the sender of email id(I have a requirement to put a different person's email id than servicenow instance creator's email id) and its content? Also could you please elaborate 3rd step. I do not see the gs.addEventQueue function. I tried using gs.eventQueue('x_104123_needlt.EmailEvent1'); but this is not sending email.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 06:24 AM
You need to pass your parameters correctly in the gs.eventQueue().
gs.eventQueue() contains 4 parameters which are as follows:
name: name of the event,
object: record for which you want the notification to get triggered, you can get your record object from the script include.
parm1: first parameter of the event (it can be a string value (email, name etc.)
parm2: second parameter of the event (it can be a string value (email, name etc.)
so your code should be something like this:
gs.eventQueue('x_104123_needlt.EmailEvent1',object record,'email of reciever','keep it empty string or pass any value which you want to send in the parameter');
Then in your notification settings you can select 'Event parm 1 contains recipient' or 'Event parm 2 contains recipient' checkbox. Based on your code you can do the selection. These two checkbox you should be able to see in the advance view of your notification's 'Who will receive' section.
Please mark this as correct and helpful if it solved your query.
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2023 09:56 AM - edited 06-01-2023 01:15 AM
Hello Thank you for your response
I will tell what I have done.
1. I created an Event Registry simply.
2. I created a Notfication
3. I created a Script Include and there I used
gs.eventQueue('x_8041114_needlt.EmailEvent1',current,'abc@gmail.com','axyz@gmail.com');
Update
Now I am able to send the email but I have to use the glideobject as 2nd parameter. But I do not want to use that. I do not want to use glideobject because my business logic doesn't need it. I want to use eventQueue() in a way that I pass the event name that will be fired, and some normal parameters but no glideobject. How should I write eventQueue();