Create a problem record when Incident is Resolved and priority is Critical.

anubhavr
Giga Expert

I have to create a problem record when Incident state is resolved and priority is '1-Critical'. I have tried it using business rule but i am getting an error.

The Error is:- Unique Key violation detected by database (Duplicate entry '778bdfe6db4122005a91d421cf96193c' for key 'PRIMARY')

My business rule scripts is:-

When to run:- State is resolved AND prioirity is 1-critical AND problem_id is empty.

Script :-

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

var prob = new GlideRecord("problem");

prob.short_description = current.short_description;

prob.cmdb_ci = current.cmdb_ci;

prob.priority = current.priority;

//gs.addInfoMessage(prob.work_notes);

//gs.addInfoMessage(answer);

var sysID = prob.insert();

current.problem_id = sysID;

var mySysID = current.update();

gs.addInfoMessage("Problem " + prob.number + " created");

action.setRedirectURL(prob);

action.setReturnURL(current);

})(current, previous);

After testing a problem record is created but still above error is coming. what is this error and how to correct it???

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Anubhav,



Can you turn off this BR and check once. If the issue still exists then there must be current.update() line in BEFORE Business rule on the table.


Please check for the same on your instance once.


http://wiki.servicenow.com/index.php?title=Business_Rules_Best_Practices


View solution in original post

9 REPLIES 9

Hi Chuck,



I am looking something like:


I have an existing record in a table, I want to insert the same record entry in another table if some condition matches.


Can I do it using the sys_id of that entry? Can you please share some code?



Thanks


Jyo


Hi Jyoti,



I have done similar kind of requirement but using button called 'Copy Incident' to copy some field values in new record. I dont think we can do it using directly by sys_id. U can try business rule for your requirment.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Anubhav,



Can you turn off this BR and check once. If the issue still exists then there must be current.update() line in BEFORE Business rule on the table.


Please check for the same on your instance once.


http://wiki.servicenow.com/index.php?title=Business_Rules_Best_Practices


Abhinay Erra
Giga Sage

Run this in After Business rule and use prob.initialize();


Abarna Dhanapal
Tera Contributor

Hi

How to configure without business rule, To create problem record when incident is resolved and priority is P1 and P2 in DOP Instance.