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 12:30 PM
Hi,
If you have declared the rtrn variable your script should look like this, right?
var DBHostname = ${DBinfo[*].DBhost};
var DBServiceName = ${DBinfo[*].Servicename};
var pval;
var rtrn;
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;
If I follow that logic and connect it your variables in the previous step. You are trying to fetch the properties attribute of the first matching CI in the cmdb_ci_unix_cluster_resource table where the Name contains "FINOLTIT" and has a Cluster reference with a Name that contains "LVLR4ORC3041Z".
If no such CI exists or if the properties attribute is empty, the returned value would be empty.
Can you log out the values using
gs.log (serv);
gs.log (host);
gs.log (pval);
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 02:34 PM
Hi Niklas,
Based on condition, Record is available in table. It is printing the same while running via background script. However in Pattern gs.log is giving below error .
Thanks,
Mehak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2023 10:21 PM
Hi,
Yes, sorry about that. Seems the logic in the script is correct but doing the gliderecord call in the pattern step is not allow due to it running on the MID server. You need to use a Pre processing script.
Here is a good blog article about it.
https://www.servicenow.com/community/in-other-news/using-gliderecord-scripting-in-service-mapping-pa...
Regards,
Niklas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 01:20 AM
Hi Niklas,
I tried below code for Pre processing script where I'm trying to pass all the records of unix cluster table into the pattern. So that I can filter them in pattern.
But this variable "customer_db_server" is not available in pattern.
As per below link provide by you this variable should automatically available under temporary variable in pattern.
Pls advice.
Pls see the below code for Pre processing script.
Thanks,
Mehak