"Unique Key violation detected by database " - Error Message

MS17
Tera Contributor

Hi All,

I have created new BR to add all Parent CIs into "Affected CI" Related list based on CI we have selected on configuration item field.

I got the error message when I am updating the CI on change record. I have checked some community posts that it is because of "current.update()" used in BR. I have checked that as well, we are not using it in BR. Can anyone please help me what could be the cause of this issue?

 

aff ci.PNG

 

4 REPLIES 4

Matthew Smith
Kilo Sage

Can you post the script of your new Business Rule please?

Hi,

I have written below script.

BR:

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

var uniqueOutageSysIDs;
if (getTableExtensions('cmdb_ci_server').indexOf(current.cmdb_ci.sys_class_name) != -1) // CI class is a Server.

    uniqueOutageSysIDs = new PopulateAffectedCI().ServerCI(current);
}

gs.addInfoMessage('Affected CIs are attched to the Affected CIs tab');

})(current, previous);

Script Include:

ServerCI: function(chg)
    {
         var ci_app_to_server_gr = new GlideRecord('cmdb_rel_ci');
        ci_app_to_server_gr.addEncodedQuery('child=' + chg.cmdb_ci);
        ci_app_to_server_gr.query();
         while (ci_app_to_server_gr.next())
        {
            var ser = new GlideRecord('task_ci');
            ser.initialize();
            ser.task = chg.sys_id;
            ser.ci_item = ci_app_to_server_gr.parent; // Inserting all parent CIs
            ser.xml = "<auto_generated>true</auto_generated>";
            ser.insert();
        }
    },

Pavankumar_1
Mega Patron

Hi @MS17 ,

could you please share the business rule script?

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Pavankumar_1
Mega Patron

Hi @MS17 ,

refer below link it is one of the scenarios. May be other Business rule which is causing this conflict.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0751326

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar