- 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 09:11 AM
Hi @ankur bawiskar
Please help me on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 09:23 PM
Hi, can you explain why you need to trigger a notification before the email address change is saved?
What happens if the user changes their mind and aborts the update(s) that they have made to the record in the UI?
I would not recommend this as best practice,
but if you must deliver this as a solution then you would simply need to use GlideAjax to trigger a sysevent, passing in the email address as an event parameter and then consume it with a notification.
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/client/c_GlideAjaxAPI?navFilter=glideajax
https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideSystemAPI#r_GS-eventQueue_S_O_S_S_S?navFilter=eventqueue
https://docs.servicenow.com/bundle/sandiego-servicenow-platform/page/administer/notification/task/t_CreateANotification.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 10:05 PM
Hi Tony,
i am asking the solution for bank applications for when ever user enter their details like for mobile number validations i want to send otp for that mobile and also for email validation i want to send a email otp for that email vallidation thatswhy i am asking this
for this i am created a reccord producer for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2022 10:45 PM
I would have thought that this scenario would have required that the data changes were recorded\audited, but if you need to trigger in real time without saving, then an onChange() client script triggering a sysevent via a GlideAjax call would be the method that I would use.
