send email from UI action with choice in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 02:07 AM
I have a UI action (test). I want a functionality , when ever I click on this UI action there should be a option (a,b,c) to select and recipient and later on upon the selection an email should be send to the a,b,c team .
How should I Achieve this functionality , Any suggestion will be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2024 03:59 AM
hi @gourav_toonwal ,
Please follow this steps
1. create event in 'sysevent_register' table for specific table in my case i am doing for RITM
2. then create notification on RITM table then
3. the create ui action 'Send Email'
script:
function email(){
var dialog = new GlideModal("email_reason_ui_page"); // The name of your UI Page
dialog.setTitle("Enter Reason for Republish");
dialog.setPreference('sys_id', g_form.getUniqueValue());
dialog.render();
}
4. create ui page :html
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_sys_id" value="${RP.getWindowProperties().get('sys_id')}"/>
<input id="record_sys_id" type="hidden" value="${jvar_sys_id}" />
<style>
.required:before {
content:"* ";
color: red;
}
</style>
<g:evaluate var="jvar_sysId" expression="RP.getWindowProperties().sysparm_id"/>
<g:ui_form>
<input type="hidden" name="selected_record_sysId" value="${sysparm_id}"/>
<p class="required">Please select user to assign selected records</p>
<g:ui_reference name="new_user_id" id="new_user_id" table="sys_user_group" mandatory="true^active=true"/>
<br>
</br>
<br>
</br>
<g:ui_reference name="new_user_id1" id="new_user_id1" table="sys_user_group" mandatory="true^active=true"/>
<br>
</br><br>
</br>
<g:ui_reference name="new_user_id2" id="new_user_id2" table="sys_user_group" mandatory="true^active=true"/>
<br>
</br>
<br>
</br>
<g:dialog_buttons_ok_cancel ok="return validateForm()" cancel="return onCancel()"/>
</g:ui_form>
</j:jelly>
client script
function onCancel(){
GlideDialogWindow.get().destroy();
}
function validateForm(){
var reason =$j('#new_user_id').val();
var reason1 =$j('#new_user_id1').val();
var reason2 =$j('#new_user_id2').val();
var main=reason +','+reason1+','+reason2;
var sys_id = $j('#record_sys_id').val();
var grajax = new GlideAjax('IncidentUpdate');
grajax.addParam('sysparm_name', 'EmailTrigger');
grajax.addParam('sysparm_userId', sys_id);
grajax.addParam('sysparm_user',main);
grajax.getXMLAnswer(fetchvalue);
function fetchvalue(response) {
if (response) {
alert("Email send");
}
}
GlideDialogWindow.get().destroy();
}
Script include: client callable true
var IncidentUpdate = Class.create();
IncidentUpdate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
EmailTrigger:function(){
var sysId=this.getParameter('sysparm_userId');
var reason=this.getParameter('sysparm_user');
var ritmSysid= new GlideRecord("sc_req_item");
ritmSysid.addQuery("sys_id",sysId);
ritmSysid.query();
if(ritmSysid.next()){
gs.eventQueue('ritmserq',ritmSysid,reason,gs.getUser())
}
},
type: 'IncidentUpdate'
});
Please hit helpful and accept this as a solution if it solved your problem.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 08:34 PM
Hi @gourav_toonwal ,
This solution helped you to resolve the issue , if yes please accept this as a solution.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2024 08:58 PM
what's your business requirement for this?
Is this just for your learning purpose?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader