Does Discovery bypass Business rules on cmdb_rel_ci table?

Marek10
Tera Contributor

Hello Community,

We tried to amend some discovered MS SQL DBs on the fly by copying Version from the parent MSFT SQL Instance. We tried to achieve this by a Business Rule triggered when the relationship between the two is created. When creating relationships manually the BR runs but it does not seem to trigger when Discovery creates them. I then tested on very generic BR triggering on ANY cmdb_rel_ci insert and apparently this does not trigger either. 

Does Discovery switches off/bypass BR (when creating relationships specifically)?

I am very fresh in ServiceNow development area so I might have missed some obvious thing...

Thanks in advance!

8 REPLIES 8

valarmathi_kann
ServiceNow Employee
ServiceNow Employee

Hi,

Does Discovery switches off/bypass BR (when creating relationships specifically)?

        To answer to your question, 'Discovery' doesn't switch off any Business rules

 

Since your business rules are not triggered, I wanted to confirm few things.

        1. Can you try inserting a record from background scripts and check the BR is triggered?

        2. Please check whether you have 'gr.setWorkflow(false)' set in the script while creating the relationship. This will stop any business rules to be triggered.

 

Please mark this answer correct & helpful if you find this helpful.

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,

To find this we have to check on many script includes and sensor script where they are using setWorkflow(false) or not.

 

But OOB i believe discovery doesnot block triggering of BR. You can check creating a simple BR which triggers log and condition should match obviously.

THanks,
Ashutosh

Marek10
Tera Contributor

Thanks Valarmathi and Ashutosh for your responses!

I have now tested on my PDI and it seems the BR does not trigger when Discovery creates relationships here either. It does when I create manually or when I create via background script.

The BR is very simple for that purpose:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	gs.info("MMDEBUG: Rel created: type " + current.type);

})(current, previous);

The background script is also simple:

var gr = new GlideRecord('cmdb_rel_ci');
gr.initialize();
gr.setWorkflow(false);
// hardcoded sys id
gr.parent='adfd748437201000deeabfc8bcbe5d2f'; 
gr.child='0c43bc4fc61122750182c132411702f2'; 
gr.type='1a9cb166f1571100a92eb60da2bce5c5' ;
var res = gr.insert();
gs.info("MMDEBUG: BK SCR1: rel created: "+res);


var gr2 = new GlideRecord('cmdb_rel_ci');
gr2.initialize(); 
// hardcoded sys id
gr2.parent='adfd748437201000deeabfc8bcbe5d2f'; 
gr2.child='0c43bc4fc61122750182c132411702f2'; 
gr2.type='25242fb2377a9200738d021a54990e88' ;
var res = gr2.insert();
gs.info("MMDEBUG: BK SCR2: rel created: "+res);

And the result is:

*** Script: MMDEBUG: BK SCR1: rel created: 185fe1e0dba7b300c5c36a494896192d
*** Script: MMDEBUG: Rel created: type 25242fb2377a9200738d021a54990e88
*** Script: MMDEBUG: BK SCR2: rel created: 585f65a4dba7b300c5c36a4948961951

And the same I can see in syslog. Thus I learnt setWorkflow() is local to the GlideRecord it was run within and not global.

I found 4 occurrences of setWorkflow(false) in Discovery Script Includes but none of these is in cmdb_rel_ci context... keep looking. If you can offer more hints/guidance I will be grateful! Thanks in advance!

Hi,

 

Can you try removing the below line from the above script and try to run the same

gr.setWorkflow(false);

or set gr.setWorkflow(true);  --> This enables the business rule to be triggered.

 

 

Please mark this answer correct & helpful if you find this helpful.