how to include a client script in ui page of servicenow

1k Views Asked by At

I need a help like suppose I have a simple html ui page in ServiceNow. I want to include a client script. How to do this? I tried using

 <script src="/sys_script_client.do?sys_id=123456"></script>

but it did not work

<html>
    
<body>

<h1>The input attribute</h1>
<script src="/sys_script_client.do?sys_id=123456"></script> 
<form action="/action_page.php">
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname"/><br/><br/>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname" disabled="disabled"/><br/><br/>
    
  <input type="submit" value="Submit"/>
    <a href="https://dev1234.service-now.com/x_1234_needlt_index2.do">link</a>
</form>
    
    <p id="pid1">p1</p>
    <button onclick="function1()">Click me</button>

</body>
</html>
    document.getElementById("pid1").innerHTML="p1 is changed by client script of same page";
}
1

There are 1 best solutions below

1
On

Calling an existing client script from a UI page doesn't really make sense. A saved client script is tied to a specific table and trigger. Your UI page doesn't have that limitation.

What you are likely wanting to do is call a script include from the UI page... That you can do using the GlideAjax method to call that specific script include.

Here's a link on details of running script include from UI page... ServiceNow UI Page GlideAjax