- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-12-2022 11:56 PM
Hi all ,
how to trigger notification using script include and onchage client script.
i have a requirement that when user enter email id and moved to next field then i wannt to trigger a notification to that email.
please help me on this how to write a code.
Solved! Go to Solution.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-17-2022 12:00 AM
Hi
After going through your comments below, please follow the steps below to achieve your requirement:
1) Create a On Change Catalog Client Script on your Catalog Item or Record Producer on your Email Variable which ever you have created and use the script below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue) {
var gaEmail = new GlideAjax('triggerNotif');
gaEmail.addParam('sysparm_name', 'sendNotif');
gaEmail.addParam('sysparm_email', newValue);
gaEmail.getXMLAnswer(_handleResponse);
function _handleResponse(response) {
var answer = response;
if (answer == true) {
g_form.addInfoMessage('Email has been sent to your Email ID');
}
}
}
}
2) Create a Client Callable Script Include and try the script below:
var triggerNotif = Class.create();
triggerNotif.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sendNotif : function(){
var getEmail = this.getParameter('sysparm_email');
var gr = new GlideRecord('sys_email');
gr.initialize();
gr.user = getEmail;
gr.type = 'send-ready';
gr.notification_type = 'SMTP';
gr.subject = 'Enter the Subject of your Email';
gr.recipients = getEmail;
var success = gr.insert();
if(success){
return true;
}
},
type: 'triggerNotif'
});
Please try this in your lower environment first, I have not tested it.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-13-2022 10:56 PM
HI can you send me the sample code for that how to pass parameters in the script include
and also send me the smaple code for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-14-2022 02:38 AM
Steps
- Link the email notification be fired by an event.
- Use GlideAjax from the script include to fire the event.
- That will send the notification.
I hope you are aware on configuring notifications, event and scripting on GlideAjax
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-17-2022 08:05 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-17-2022 12:00 AM
Hi
After going through your comments below, please follow the steps below to achieve your requirement:
1) Create a On Change Catalog Client Script on your Catalog Item or Record Producer on your Email Variable which ever you have created and use the script below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue) {
var gaEmail = new GlideAjax('triggerNotif');
gaEmail.addParam('sysparm_name', 'sendNotif');
gaEmail.addParam('sysparm_email', newValue);
gaEmail.getXMLAnswer(_handleResponse);
function _handleResponse(response) {
var answer = response;
if (answer == true) {
g_form.addInfoMessage('Email has been sent to your Email ID');
}
}
}
}
2) Create a Client Callable Script Include and try the script below:
var triggerNotif = Class.create();
triggerNotif.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sendNotif : function(){
var getEmail = this.getParameter('sysparm_email');
var gr = new GlideRecord('sys_email');
gr.initialize();
gr.user = getEmail;
gr.type = 'send-ready';
gr.notification_type = 'SMTP';
gr.subject = 'Enter the Subject of your Email';
gr.recipients = getEmail;
var success = gr.insert();
if(success){
return true;
}
},
type: 'triggerNotif'
});
Please try this in your lower environment first, I have not tested it.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
