setWorkflow(false) not working in script

AndyB5000
Mega Guru

I have a script that we use that allows us to quickly reclassify CIs, basically move them from one table to another, and I am using the line setWorkflow(false); to prevent the business rules from triggering, but for some reason it is not working and the BRs are firing anyways..

 

var queryStringCI = 'asset_tagINAF268729,AF268723,ADM00117,10794812,10794187,10657191,10657190,';
var CIchg = new GlideRecord('cmdb_ci');
CIchg.addEncodedQuery(queryStringCI);
CIchg.setLimit(10);
CIchg.query();
gs.info("----CMDB\t" + CIchg.getRowCount());
while(CIchg.next()){
CIchg.sys_class_name = 'cmdb_ci_ip_switch'; //table name of class changing too
CIchg.setWorkflow(false);
CIchg.update();
}

Thanks in advance for the assistance...

Andy

18 REPLIES 18

AndyB5000
Mega Guru

the BR's appear on the lower tables in the CI hierarchy...example cmdb_ci_computer, cmdb_ci_server.

Because the BR does not appear at the cmdb_ci level prevent the line from stopping the BR's from running.

 

@AndyB5000 

That's correct it might be disabling only the Parent BR and not the child BRs

Why not do this

1) for each while get the class name and then query that table with the asset tag and then use setWorkflow(false) just before the update

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

AndyB5000
Mega Guru

Ankur,

Makes sense, so I modified the code down to the child tables and the BR still triggered.  The record is currently classified as Network Gear and is changing to IP Switch.  When I run the below script the BRs still trigger.

 

var queryStringCI = 'asset_tag=AF268729';
var CIchg = new GlideRecord('cmdb_ci_netgear');
CIchg.addEncodedQuery(queryStringCI);
CIchg.setLimit(10);
CIchg.query();
gs.info("----CMDB\t" + CIchg.getRowCount());
while(CIchg.next()){
CIchg.sys_class_name = 'cmdb_ci_ip_switch'; //table name of class changing too
CIchg.setworkflow(false);
CIchg.update();
}

 

Thanks.

Andy

@AndyB5000 

If there are any BRs on the child table then they should stop

There is mistake in your function name

Try this and it should work fine

var queryStringCI = 'asset_tag=AF268729';
var CIchg = new GlideRecord('cmdb_ci_netgear');
CIchg.addEncodedQuery(queryStringCI);
CIchg.setLimit(10);
CIchg.query();
gs.info("----CMDB\t" + CIchg.getRowCount());
while(CIchg.next()){
CIchg.sys_class_name = 'cmdb_ci_ip_switch'; //table name of class changing too
CIchg.setWorkflow(false);
CIchg.update();
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

still did not work, updated the line to show setWorkflow(false); and ran the script as a background script with the glide record calling the table the BR resides on and it still triggers the BR.