- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2017 07:31 AM
Hi all,
I have field with type "Script - Plain" on my custom table and would like to check the javascript object in the field.
For example, I would like to get the row/line number for the property "billable" in a server-side script.
See please picture below. In this case, I would like to get number "3", because property "billable" is on the third line.
Do you have any ideas please?
Do you know if there is any server-side API for script editor?
(When you are making javascript errors, the script editor is providing you the line number, but I assume this is client-side check)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2017 08:07 AM
You can write a script on your table like below:
------------------------------------------------------------------------------------------------------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var line = "-";
var str = current.script.split("\n");
for(var i=0; i<str.length; i++){
if(str[i].indexOf("How are you") > -1){
line = i +1;
}
}
gs.addInfoMessage("Found on Line number "+line);
})(current, previous);
------------------------------------------------------------------------------------------------------------------
I ran the above script on the below script file:
---------------------------------------------------------------------------------------------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.addInfoMessage("Hi");
gs.addInfoMessage("Hello");
gs.addInfoMessage("How are you");
})(current, previous);
----------------------------------------------------------------------------------------------------------
Kind regards,
Sourabh D

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2017 08:01 AM
Hello Peter,
Please check for API GlideScopedEvaluator(). More info here.
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=GlideEvaluator-evaluateScript_GR_S_O
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 02:54 AM
Hi Pradeep,
I did not find any useful script in GlideScopedEvaluator API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2017 08:07 AM
You can write a script on your table like below:
------------------------------------------------------------------------------------------------------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var line = "-";
var str = current.script.split("\n");
for(var i=0; i<str.length; i++){
if(str[i].indexOf("How are you") > -1){
line = i +1;
}
}
gs.addInfoMessage("Found on Line number "+line);
})(current, previous);
------------------------------------------------------------------------------------------------------------------
I ran the above script on the below script file:
---------------------------------------------------------------------------------------------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.addInfoMessage("Hi");
gs.addInfoMessage("Hello");
gs.addInfoMessage("How are you");
})(current, previous);
----------------------------------------------------------------------------------------------------------
Kind regards,
Sourabh D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2020 06:30 AM
//This is run in background script - genrates URL and finds the line number of the search keyword
var msg = '';
var currentUrl = gs.getProperty('glide.servlet.uri');
var gr = new GlideRecord('catalog_script_client');
gr.addEncodedQuery('active!=false^scriptLIKEGlideRecord');
gr.query();
gs.print(gr.getRowCount());
while(gr.next())
{
var strtemp = gr.script;
var str = strtemp.split('\n');
var line = 0 ;
for(var i=0; i<str.length; i++)
{
line = line + 1;
if(str[i].indexOf("GlideRecord") > -1)
{
msg += "CLIENT SCRIPT : "+ gr.name + "***********" + "line : " + line + "*********" + str[i].trim() + '\n' + currentUrl+gs.generateURL('catalog_script_client', gr.sys_id) + '\n'+ '\n';
}
}
}
gs.print(msg);