How to trigger an event to email using client script on service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 09:18 PM
Need to trigger an event to email using client script in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2022 09:33 PM
Hi
Check this link,It will help you.
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2025 06:11 AM
Please refer to my article to resolve your issue.
Trigger email/event on field change using client script (without saving form)
If you find my answer correct and helpful, kindly mark it as such.
Thank you,
Nilesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 10:01 AM
Hi @Shaik Ibrahim k ,
In ServiceNow's Service Portal, Client Scripts (written in JavaScript and running in the browser) cannot directly send emails or trigger server-side events, because they run on the user's browser and do not have access to the server’s email functionality.
However, you can trigger an event (which sends an email) from a client script by using a combination of:
- Client Script (to capture the action and call a Script Include or GlideAjax)
- Script Include (server-side logic to trigger an event and send an email)
- Event Registration and Email Notification based on that event
Please follow step by step:
- Register an Event
Go to System Policy > Events > Registry and create a new event, e.g.:
- Name: custom.email.trigger
- Table: e.g., sc_req_item (or any applicable table)
- Description: Triggered from portal to send email
2. Create an Email Notification
Go to System Notification > Email > Notifications:
- Trigger on the event: custom.email.trigger
- Define the conditions
- Choose recipients
- Create the email content
3.Create Script Include
Go to System Definition > Script Includes and create one like this:
var PortalEmailTrigger = Class.create();
PortalEmailTrigger.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sendEmail: function() {
var gr = new GlideRecord('sc_req_item'); // Use appropriate table
if (gr.get(this.getParameter('sys_id'))) {
gs.eventQueue('custom.email.trigger', gr, gs.getUserID(), '');
return "Event triggered";
}
return "Record not found";
}
});
Ensure it's Client Callable
4. Client Script (Service Portal Widget or Catalog Client Script)
Use this code in your Catalog Client Script or Widget Client Script:
function triggerEmail(sys_id) {
var ga = new GlideAjax('PortalEmailTrigger');
ga.addParam('sysparm_name', 'sendEmail');
ga.addParam('sys_id', sys_id); // Replace with appropriate sys_id
ga.getXMLAnswer(function(response) {
console.log(response); // Optional: show response
});
}
// Call this function based on some user action, e.g., button click
triggerEmail(g_form.getUniqueValue()); // For Catalog Client Script
Thanks and Regards,
Chiranjeevi R
Please mark as Correct Answer/Helpful, if applicable.
Chiranjeevi
ServiceNow Developer | | ITSM | | ServiceNow Discovery | | Event Management | | Service Mapping | | CMDB
Please mark as Correct Answer/Helpful, if applicable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2025 10:20 AM
Hi Shaik,
First create a client-callable Script Include that contains the server-side logic. Then, in the widget’s Client Script, use the GlideAjax object to call the Script Include method. When the server responds, the result can be processed and displayed in the widget using AngularJS bindings. The widget’s HTML template typically includes a button or trigger to initiate the call. This approach allows you to securely execute server-side logic (like sending emails or fetching data) from the client side in Service Portal.
Regards,
Pradeep Adiga