ServiceNow Script / ScriptInclude
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2023 03:39 AM
We are running a GlideQuery .
wherein we are checking a variable which has concatenation.
if the 'concat' value matches the correlation in the table it would update the found record else insert a new record.
/*************************************************************/
var pres = presourceID;
gs.info('testparent' + pres);
var childr = dresourceID;
gs.info('testchild' + childr);
//var concat = pres.concat(childr);(we tried concatenating like this too .
var concat = pres + "-" + childr; (we are concatenating two variables and storing it in var cancat)
gs.info('line262' + concat);// (we are able to print this log too)
var gr = new GlideRecord('cmdb_ci_network_interface_device');
gr.addQuery('correlation_id', concat);
gs.info('printtheconact'+concat);// able to print this value
gr.query();
gs.info("@@printcount:"+gr.getRowCount()); // this is giving 0 row count and script is stopped
if (gr.next()) {
gr.correlation_id = concat;
gr.device_type = dresourceType;
gr.name = resourceName;
gr.attributes = this.resourceCharacteristics(dspecfCha) + "";
if (dspecfStatus == 'active') {
gs.info("SRIMS10");
gr.operational_status = 1;
gs.info("SRIMS20");
} else {
gr.operational_status = 2;
gs.info("SRIMS21");
}
gr.update();
} else {
gr.initialize();
gs.info("SRIMS231");
gr.correlation_id = concat;
gr.name = resourceName;
gr.device_type = dresourceType;
gr.sys_domain = '85497d2b472c991065296439736d437b'; // NETWORK DOMAIN
gr.attributes = this.resourceCharacteristics(dspecfCha) + "";
if (dspecfStatus == 'active') {
gs.info("SRIMS11");
gr.operational_status = 1;
gs.info("SRIMS12");
} else {
gr.operational_status = 2;
gs.info("SRIMS13");
}
var getIDChild1 = gr.insert(); // record insertion//
gs.info("SRIMSchild1sys:" + getIDChild1);
}
/**********************************************************************/
I want to understand why the query is not working.
If the concat value is not found it should insert but the script stops at the query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2023 04:31 AM
Hi,
Is cmdb_ci_network_interface_device a valid table?
Also, you are trying to set gr.name to a variable called resourceName which is not set in the script.
Regards,
Niklas