Unique Key Violation Detected by Database

Rob Sestito
Mega Sage

Hey SN Comm Team,

I am all of a sudden getting the following error:

find_real_file.png

I received this after I made a change to the following BR:

find_real_file.png

**Newest code commented out for now when trying to figure this out**

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

	var d2 = new GlideDateTime(current.getValue('u_first_letter_sent'));
	d2.addDaysLocalTime(22);
	current.u_second_letter_sent=d2;
	
	var d3 = new GlideDateTime(current.getValue('u_second_letter_sent'));
	d3.addDaysLocalTime(15);
	current.u_third_letter_sent=d3;
	
	//var termLetter = new GlideDateTime(current.getValue('u_third_letter_sent'));
	//termLetter.addDaysLocalTime(8);
	//current.u_authorize_termination_email_sent=termLetter;

})(current, previous);

Even with it commented out, I get the same error repeating when I try to create a case using the HR Service that goes with this BR. I have seen some stuff on the SN Comm talking about current.update - But I don't have that exact script being used. Can someone help me out as to why this error is occuring?

u_authorize_termination_email_sent field is new as of today for this also

Cheers,

-Rob

1 ACCEPTED SOLUTION

Found the issue - system property sn_hr_core.auto_categorization. When I was trying to test by making a LOA Claim case, I was getting those errors I showed in my initial post. The second error "failed to insert record" had me thinking that no case was created. This morning I logged in and saw 9 "test" cases created by me from last yesterday. For some reason when I was trying to create a case using LOA Claim service, the cases were being created under General Inquiry service, using the Total Rewards numbering system and short description.

find_real_file.png

So, these cases were created under the main HR Case COE - Really odd!!

When I jump into one of the cases, I see the following under activities:

find_real_file.png

That makes no sense - if I am selecting the actual service from the Case Creation Page, why would this property kick in to "help".

I went to the property and changed the value to false - created the LOA Claim case just fine. I think I read somewhere that this property has a flaw, and was fixed in Orlando (but I could be wrong and thinking about something else).

Either way, things seem to be working normal now that the property is set to false.

Thanks,

-Rob

View solution in original post

10 REPLIES 10

Allen Andreas
Administrator
Administrator

If you set the BR to inactive, do you still get the error?

I'm not seeing how the date/time would have this error.

Either way, you can try to adjust script like:

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

	var d2 = new GlideDateTime();
        var fLetter = current.getValue('u_first_letter_sent');
        d2.setValue(fLetter);
	d2.addDaysLocalTime(22);
	current.u_second_letter_sent = d2;
	
	var d3 = new GlideDateTime();
        var sLetter = current.getValue('u_second_letter_sent');
        d3.setValue(sLetter);
	d3.addDaysLocalTime(15);
	current.u_third_letter_sent = d3;
	
	//var termLetter = new GlideDateTime(current.getValue('u_third_letter_sent'));
	//termLetter.addDaysLocalTime(8);
	//current.u_authorize_termination_email_sent=termLetter;

})(current, previous);

And just to ensure that the u_first_letter_sent and u_second_letter_sent are both date/time fields?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Setting BR to inactive does give me the same error. This BR is not new - I have had this for a little while now - just came across the error when I was asked to add in the new Authorize Term field. When I went to test using the correct HR Service this deals with, the error happened. I just sent the BR to inactive, and I do receive the same error.

Those Letter fields are Date type fields, not Date/Time.

I also adjusted the script to your suggested script, and got the same error.

Thoughts on this error now that I have inactivated the BR?

Thanks,

-Rob

So if you've had the BR and this script is in the BR, and making the BR inactive, still gives this error, then it's not the BR.

So then something else that has changed would be causing this? What else have you worked on with this?

And and far as the date and date/time fields, you're using GlideDateTime, so that's for date/time fields.


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

All I did on this table sn_hr_core_case_total_rewards - was add that new field today, added additional code to the BR, and try testing by creating a case under the hr service leave of absence Claim. That was when the error started occurring.

I checked on that table to cases created today using the same service, and there was 5 in total opened today. If a normal user opening those cases would have gotta that error, I would have heard about it. This is very strange how it just started happening.

I also went to one of these cases opened today that uses this BR to calculate the dates - I enter in a date for the First Letter field, save the record, and the Second and Third letter fields populate with the future date calculations. Again, this is strange why I am getting the error.

I will try to see what I can find out.

-Rob