Urgent assistance with Execution of UI action from Schedule Job

sunny27
Tera Contributor

Hi All, 

I have requirement where I need to create a schedule Job which runs every 30mins and it should execute a "Test connection" UI action in it.  As per the UI action's result a notification should send to certain group.

UI Action: (Onclick : testAccountConnection(); )

var title = getMessage('Connection Test');

function testAccountConnection() {

var gm = new GlideModal('email_connection_test', false /*read-only*/ );
gm.setTitle(title);
gm.setWidth(500);
gm.render();

}

 

I have tried to copy paste the UI action's script in Script Include. And updated schedule job with "new emailAccountTestConnection().emailTestConnection();"

In Script Include : 

var emailAccountTestConnection = Class.create();
emailAccountTestConnection.prototype = Object.extendsObject(AbstractAjaxProcessor, {

emailTestConnection: function() {

var title = getMessage('Connection Test');
var gm = new GlideModal('email_connection_test', false /*read-only*/ );
gm.setTitle(title);
gm.setWidth(500);
gm.render();
return gm;
},

type: 'emailAccountTestConnection'
});



But I'm facing com.glide.script.RhinoEcmaError: "getMessage" is not defined or com.glide.script.RhinoEcmaError: "GlideModal" is not defined.

 

Could you please advice any preferable steps to complete this task ? Its quite urgent now. 

 

 

Thank you

 

1 ACCEPTED SOLUTION

DrewW
Mega Sage
Mega Sage

You are not going to be able to run a client side UI action via a scheduled job.  Especially one that opens a dialog.  You are going to have to understand how the UI Page/UI Macro "email_connection_test" works and do the same thing that does in your scheduled job.

View solution in original post

6 REPLIES 6

DrewW
Mega Sage
Mega Sage

You are not going to be able to run a client side UI action via a scheduled job.  Especially one that opens a dialog.  You are going to have to understand how the UI Page/UI Macro "email_connection_test" works and do the same thing that does in your scheduled job.

sunny27
Tera Contributor

Hi, Thank you for the update. 

I did tried to find the UI Page/UI Macro "email_connection_test" in both tables. But the details were not found. Is there any other way to find this UI page? 

Is this a ServiceNow built UI Action that is part of some App that ServiceNow built?  If so then you may not be able to get at it.  ServiceNow does not make all of their UI Pages/Macros available to us.

Ratnakar7
Mega Sage
Mega Sage

Hi @sunny27 ,

 

you can consider the following steps:

 

-> Create a Script Include and add the 'GlideModal' and 'GlideRecord' classes to it.

Example:

 

 

var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
   initialize: function() {
   },

   testAccountConnection: function() {
      var gr = new GlideRecord('table_name');
      // Perform your test connection logic here
      // Use gr.setValue() or gr.update() to update records in the table
      gs.eventQueue('my_event_name', gr, 'my_parameter_value');
   },

   type: 'MyScriptInclude'
}

 

 

-> Create a Business Rule that listens to the 'my_event_name' event and sends the notification to the desired group based on the event parameters.

Example:

 

 

gs.event.on('my_event_name', function(gr, parameter) {
   // Send notification to group based on the event parameters
});

 

 

-> Create a scheduled job that invokes the 'testAccountConnection' function of your Script Include.

Example:

 

 

var myScriptInclude = new MyScriptInclude();
myScriptInclude.testAccountConnection();

 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar