Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Run SQL Server queries in scripts background

Vimal Priya
Giga Guru

Hi All,

I have written some SQL queies but it is not working when i checked it with script background , I am getting some errors .

gs.sql("(select category from incident;)"):

[0:00:00.000] Script completed in scope global: script


Javascript compiler exception: invalid label (<refname>; line 1) in: gs.sql("(select category from incident;)"):

if i gives as gs.sql("select category from incident");

[0:00:00.002] Script completed in scope global: script


SQL error: FAILED TRYING TO EXECUTE ON CONNECTION 5: select category from incident Syntax Error or Access Rule Violation detected by database (Table 'dev14756_1.incident' doesn't exist) : no thrown error

gs.sql("(select count (*) ,caller_id.vip from incident where caller_id.vip="true")");


0:00:00.001] Script completed in scope global: script


Javascript compiler exception: missing ) after argument list (<refname>; line 1) in: gs.sql("(select count (*) ,caller_id.vip from incident where caller_id.vip="true")");

What will be the problem with this ?

Please Provide solution.

Thanks in advance.

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think your first and third have some syntax errors, and here's the best sql reference I could find.


http://www.servicenowelite.com/blog/2014/2/1/glidesystem-sql



Why exactly are you using gs.sql() instead of a GlideRecord query, which would be the best practice?


View solution in original post

12 REPLIES 12

Just notice something else, you're trying to dot walk in a SQL statement. That will not work in SQL!


The other input is that i don't believe that caller_id is a field of the task table.



Something like the following one will work:



gs.sql("Select count(*), state from task WHERE sys_class_name='incident' GROUP BY state");



Thanks,


Berny


Vimal Priya
Giga Guru

Thanks For Your Valuale Inputs Berny Alvarado @brad tilton @tony barratt@gurpreet