
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 06:25 AM
Hi Team,
Could you please check, what I am missing in my UI Action Code.
Issue:
The prompt window is coming, but Notification is Not getting Triggered.
Requirement:
Table: SC_task, Need To have a Prompt window and if we enter some value, Notification will get trigger.
Code:
Regards,
Priya
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 11:34 PM
Glad that it worked. Please mark answer as correct and helpful.
unfortunately you cannot send value of prompt box which user gave from client side to server side.
Also since you are not updating anything from server side just sending event you can make the UI action only client side
Approach below:
1) one user gives the email in prompt box; get the value
2) Write GlideAjax call in that client side code and pass the email, comments, record sysid
3) in the script include function updated the record using the sys_id and then get the email address given by user in prompt box and include that in event queue
Updated UI Action:
function promptUser(){
var con = prompt("Please enter some value to trigger notification");
if(con != null){
var ga = new GlideAjax('sendEmailUtils');
ga.addParam('sysparm_name', 'sendEmail');
ga.addParam('sysparm_email', con);
ga.addParam('sysparm_comments', 'Test test');
ga.addParam('sysparm_sys_id', g_form.getUniqueValue());
ga.getXML(processResponse);
function processResponse(response) {
var result = response.responseXML.documentElement.getAttribute("answer");
}
}
else{
return false;
}
}
Sample Script Include: Client Callable
var sendEmailUtils = Class.create();
sendEmailUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sendEmail: function(){
var email = this.getParameter('sysparm_email');
var comments = this.getParameter('sysparm_comments');
var sysId = this.getParameter('sysparm_sys_id');
var gr = new GlideRecord('sc_task');
gr.get(sysId);
gr.comments = comments;
gr.update();
gs.eventQueue("onboard.welcome.event", gr,gr.request_item.variables.external_contact_email);
gs.eventQueue("onboard.welcome.event.pass", gr,gr.request_item.variables.external_contact_email);
},
type: 'sendEmailUtils'
});
Mark as Correct Answer & Helpful if this solves your issue or Helpful if this is useful to you.
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
07-09-2020 08:05 AM
Use this
function promptUser(){
var con = prompt("Please enter some value to trigger notification");
if(con != null){
g_form.setValue('comments', 'Test test');
}
else{
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'my_ui_action'); // give here the action name
}
//This is how the to decide when to call server script
if(typeof window == 'undefined')
notify();
function notify(){
gs.eventQueue("onboard.welcome.event", current,current.request_item.variables.external_contact_email);
gs.eventQueue("onboard.welcome.event.pass", current,current.request_item.variables.external_contact_email);
}
Thanks,
Ashutosh Munot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 07:35 AM
You are triggering the event on Client side, make your UI action trigger the event from Server Side.
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 07:48 AM
Try below:
function promptUser(){
var con = prompt("Please enter some value to trigger notification");
if(con != null){
g_form.setValue('comments', 'Test test');
}
else{
return false;
}
}
if(typeof window == 'undefined'){
gs.eventQueue("onboard.welcome.event", current,current.request_item.variables.external_contact_email);
gs.eventQueue("onboard.welcome.event.pass", current,current.request_item.variables.external_contact_email);
// gsftSubmit(gel('sysverb_update_and_stay'));
//gsftSubmit(gel('sysverb_update'));
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 07:55 AM
Hi,
I tried but no luck.
Regards,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 08:02 AM
few corrections and updated script below
1) give action name to your UI Action - such as my_ui_action; it is empty in your case
2) updated script below
gs.eventQueue() is server side so it won't work in client side code; you need to use gsftSubmit()
then make the event trigger from server side code
function promptUser(){
var con = prompt("Please enter some value to trigger notification");
if(con != null){
g_form.setValue('comments', 'Test test');
}
else{
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'my_ui_action'); // give here the action name
}
if(typeof window == 'undefined')
sendEmail();
function sendEmail(){
// server side code to trigger event
gs.eventQueue("onboard.welcome.event", current,current.request_item.variables.external_contact_email);
gs.eventQueue("onboard.welcome.event.pass", current,current.request_item.variables.external_contact_email);
}
Kindly mark correct & helpful if it helps.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader