java script code is not working in discovery pattern

mehak1890
Tera Expert

Hi All,

I'm facing issue in below code in pattern. when I'm running this code in background script, its working fine and I'm getting output but when I'm running under pattern then I'm not getting any output.

 

var DBHostname = ${DBinfo[*].DBhost};
var DBServiceName = ${DBinfo[*].Servicename};

var pval;

var serv = DBServiceName.substring(0, DBServiceName.indexOf('.'));
var host = DBHostname.substring(0, DBHostname.indexOf('-'));


var tablename = "cmdb_ci_unix_cluster_resource";
var gr = new GlideRecord ( 'cmdb_ci_unix_cluster_resource' );

gr.addQuery('cluster.name','CONTAINS', host);
gr.addQuery('name','CONTAINS', serv);
gr.query()
if (gr.next())
{

pval = gr.properties;


}

 

rtrn = pval;

 

Pls see the below screenshot where I'm not getting any output

 

mehak1890_1-1693239369794.png

Could you pls help me on this?

 

Thanks,

Mehak

8 REPLIES 8

Niklas Peterson
Mega Sage
Mega Sage

Hi,

At the end you are assigning rtrn = pval;

 

rtrn is not a declared variable. 

 

Regards,
Niklas

 

Hi Niklas, Yes I tried this as well, I have declared rtrn variable but its not giving the value in output.

 

Thx

Mehak

Hi,

OK, a couple of questions.

What is the DBHostname and DBServiceName variables set to? Is that correctly being match to the cluster and resource names in the CMDB?

 

If you declare the variable rtrn = 'test'; 

Will 'test' be returned in the output?

 

Regards,
Niklas

Hi Niklas,

Pls see the below screenshot.

 

mehak1890_0-1693248472606.png

 

Yes, its being match to the cluster and resource names in the CMDB. I ran through background script, and its working. But when I'm running through pattern then its not.

 

Thx

Mehak