Writing a log statement from a client script.

Sue Frost
Giga Guru

I've added the Simultaneous Alert functionality written by ServiceNow Guru (Handling Simultaneous Updates in ServiceNow - ServiceNow Guru ) to my dev instance. With only minor changes, it works exactly as expected.

The request that has me stumped pertains to tracking how often this alert functionality is called.

I can't add a counter field to the record as that would trigger another update and likely cause a loop.

So adding a log statement that we can at least report on (in some fashion) sounds like the way to go. However, I can't find anything on writing to the system log from a client script. The "jslog" command writes to the JavaScript log, but that's only available while you're debugging. I need something I can check on a weekly basis to see how many records were simultaneously edited.

I'm pondering adding a new table simply for the purposes of tracking this data. My gut feeling though is that this will only be monitored for a short while and that a new table is probably tackling the issue with a sledgehammer.

Any suggestions are very much appreciated.

1 ACCEPTED SOLUTION

Daniel Draes
ServiceNow Employee
ServiceNow Employee

If you use the code provided by Mark (crossfuze / servicenowguru) there is no need for additional ajax calls.


The onsubmit function already has an AjaxCall to verify the timestamps:



        var ga = new GlideAjax('SimultaneousUpdateAlert');


          ga.addParam('sysparm_name', 'checkUpdate');


          ga.addParam('sysparm_tableName', tableName);


          ga.addParam('sysparm_sysID', sysID);


          ga.addParam('sysparm_user', g_user.userName);


          ga.addParam('sysparm_silent_request', 'true'); // don't log on the server


          ga.getXMLWait();


as is seems you only need to change sysparm_silent_request to false to make a log entry.


If not, check the Script Includes to find the one mentioned here and add your logging in there.


View solution in original post

11 REPLIES 11

senthilp
Giga Contributor

Hi,


You can try gs.log in client script and the logs are captured under 'Script log statements' module.


That was the first thing I tried:



        gs.log("Simultaneous Alert on " + g_form.sys_id);



And here's the result:



        The object "gs" should not be used in client scripts.


Yes. I agree.. I think then you should go for GlideAjax



http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#gsc.tab=0


Chris M3
Tera Guru

Your pondering is correct.   You will need to build something to make this interaction.



My design would be to create an AJAX available object for logging.   You could send the data to a new table, or simply send it to the logs.