java script code is not working in discovery pattern
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 09:21 AM
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
Could you pls help me on this?
Thanks,
Mehak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 09:32 AM
Hi,
At the end you are assigning rtrn = pval;
rtrn is not a declared variable.
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 09:52 AM
Hi Niklas, Yes I tried this as well, I have declared rtrn variable but its not giving the value in output.
Thx
Mehak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 10:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 11:49 AM
Hi Niklas,
Pls see the below screenshot.
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