gs.print not working in UI pages

mahather
Kilo Contributor

I Wants to print current record number inserted in table after click Submit button

I am new to Swericenow please help

here is code

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

      Hello Welcome to New Test Page

<table>

      <tr>

              <td> Name </td>

              <td> <input type="text" id="fname" name="fname"/> </td>

             

      </tr>

</table>

        <input type="submit" value="Save Record" onclick="return ins();"/>

<script>

                                 

                                  function ins()

{

     

var gr = new GlideRecord('x_94496_econtact_a_network_voice');

gr.initialize();

gr.csc_short_name = document.getElementById("fname").value;

gr.insert();

alert ("Record inserted");

gs.print('Incident Number is ' + number '); // Number is column name where auto number value would be generated once record inserted into table.

}

</script>

      </j:jelly>

1 ACCEPTED SOLUTION

Use the below code.



var gr = new GlideRecord('x_94496_econtact_a_network_voice');  


gr.initialize();  


gr.csc_short_name = document.getElementById("fname").value;  


var id= gr.insert();  


var gr1= new GlideRecord('x_94496_econtact_a_network_voice');


gr1.get(id);



alert ("Record inserted" + gr1.number);  



Thanks,


Jagarnath


View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Mahather,



Function print is not allowed in scope app. Use gs.debug() or gs.info() instead


But why?  This seems like such a simple function.  😞

mahather
Kilo Contributor

No it doesn't work .. please help me with sample code.. or please correct above code


Hello Mahather,





Why are you using gs.print in the script?
Do you want to log something in the system log?



As Pradeep said - gs.print does not work in scopes different than the Global one.
If you try to execute your script and only the gs.print is the problem, then you will receive a warning notification from the SNOW, informing you that gs.print does not work in custom application's scope. So you will need to use gs.info or gs.debug.



If you may skip your request of logging info in the system log, then you may simply remove gs.info from your script and try it that way.




Best Regards,


Georgi Mavrodiev



IT Consultant


Do IT Wise



You may visit us in our Web Site: www.doitwise.com