Calling client script from HTML Template's script section

fact
ServiceNow Employee
ServiceNow Employee

Hello Awesome Developers,

Please help me here.

I am developing a service portal page as I am new to this, started with a huge HTML Template with <script> and several functions in it. These functions parses the input fields from the HTML page and applies complex parsing logic. After processing, I want to store the results in a table and so need to call a client function which will then pass the data to the Server Script.

I can call the Client Script's function from the HTML using the ng-click , however I want to call the Client Script function from the <script> function. This is complaining as function_name is not defined when coded c.clientScriptFunctionName()

 

Is there a way to call the client script function Also can I put all the functions from the <script> section in to the Client Script section.

My Widget looks something like this

 

 

 

HTML Template
============
<script>
function f1(){
read the inputs from the html and parse
}
function f1(){
further processing
global_run_id = 1;
c.call_clientscriptfunction()
}
 </script>

<div class="panel panel-default">
<div class="col-sm-9"><input type="text" class="form-control" id="Readtext" /></div>
----
----

Client Script
==========
api.controller=function() {
/* widget controller */
var c = this;
c.call_clientscriptfunction = function()
{
c.data.run_id = global_run_id;
------
------
c.server.update();
}
};

Server Script:
==========
(function() {
if(input)
{
var gr = new GlideRecord('u_table');
gr.initialize();
gr.setValue('u_run_id',input.run_id);
}
})();

 

 

5 REPLIES 5

fact
ServiceNow Employee
ServiceNow Employee

Thanks!! great example to learn the basic.