Querying a custom table

ash66
Tera Contributor

I have created a script include in order to get the data from the custom table and set the value in the fields of "Impact" and "Urgency". The condition which I have put the output of the count of rows should be 1 but the output is 0. 

 

setimpactur: function(){
var service_name = this.getParameter('sysparm_service');
var category = this.getParameter('sysparm_category');
var subcategory = this.getParameter('sysparm_subcategory');
var classification = this.getParameter('sysparm_classification');
var inci = new GlideAggregate('u_incident_priority_mapping');
inci.addAggregate('COUNT');
inci.addQuery('u_service',service_name);
inci.addQuery('u_category',category);
inci.addQuery('u_subcategory',subcategory);
inci.addQuery('u_classification',classification);
inci.query();
var recs =0
if (inci.next()){
recs = inci.getAggregate('COUNT');
gs.log("inside if count of rows "+recs);
}
gs.log("outside if count of rows "+recs);
return impact1;
}

 

Can anyone help ? 

1 ACCEPTED SOLUTION

@ash66 

So  "classification " is the reason.

Check  its data type  and what did you pass to the query conditon may slove it!

 

 

Please mark my answer as correct and helpful based on Impact.

View solution in original post

4 REPLIES 4

AkshatRastogi
Mega Guru

Hi, what is impact1, its not defined anywhere in the code. Replace it with return recs if you want to return the records count.

Finally, your question is vague. Please provide more information.

newhand
Mega Sage

@ash66 

Do you means both  "inside if count of rows"  and "outside if count of rows" show  0 ?

The most possiable reason is there is no record  met your query condition.

(like a normal sql  , "count"  always returs a record even there is no data met the search condition )

 

I suggest you to print all the parameters passed to this script include and then check them.

you can fire a normal query to find out if there are any records met your parameters.

 

And by the way  "impact1" is not  defined anywhere .

Did you return a wrong variable?

 

 

 

Please mark my answer as correct and helpful based on Impact.

ash66
Tera Contributor

Yeah I tried checking the condition manually the answer of the "inside if count rows" and "outside if count rows" should "1" and I tried removing the classification condition, I got the answer as "6" which was supposed to be the answer. As soon as I am giving the classification condition the number of records in the output is coming 0 which is wrong the answer should be "1" because there is a record existing in the table

@ash66 

So  "classification " is the reason.

Check  its data type  and what did you pass to the query conditon may slove it!

 

 

Please mark my answer as correct and helpful based on Impact.