Issue with UI Action Prompt window.

Priya Gautum
Kilo Guru

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:

find_real_file.png

find_real_file.png

Regards,

Priya

 

1 ACCEPTED SOLUTION

@Priya Gautum 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

17 REPLIES 17

Hi Ankur,

Thank you for your time!!!

This script worked for me, but I have one open point on this:

  • In the Prompt user will be giving the email ID, we have to send the Notification to them also. (ex: Email ID-coming from Prompt & Variable_external_contact_email).

 

Regards,

Priya

HI,

Then you can switch this logic to UI page and send notification event from UI page.

Thanks,
Ashutosh

Hi ,

Cant, we achieve it in this code itself?

Regards,

Priya

Hi,

Its better you do this using UI page and pass this email id and do it from there.


Thanks,
ashutosh

@Priya Gautum 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader