I am receiving "Unique Key violation detected by database" Kindly help on this

Ashoka Panchal
Tera Contributor

I am receiving "

Unique Key violation detected by database ((conn=875367) Duplicate entry 'd058e75f1b503d90c0b0fc468d4bcbf3' for key 'PRIMARY')" whenever I change the due date. Below is my business rule. 
 
 
    var gr = new GlideRecord('metric_instance');
    //gr.initialize(); //current.due_date.changes()
    gr.addQuery('definition''cd55f43d1b147590c0b0fc468d4bcb0c'); 
    gr.addQuery('id', current.sys_id);
    gr.query();
    while (gr.next()) {

        if (current.due_date != previous.due_date) {
            //Increment the count field by 1

            var value = gr.value - 0;
            if (value == '') {
                // Set the initial value to 1 if it's not a number or empty
                value = 1;
            } else {
                // Increment the count field by 1
                value = value + 1;
            }
            gr.value = String(value).split('.')[0]; // Convert back to a string if necessary 
           gr.update();//
            //gr.setValue('value', String(value).split('.')[0]);
        }
 
 
If I remove gr.update(), it's not inserting any value in the metric table. If I keep gr.update(), it's working and inserting the value. But it's throwing an error with Unique key violation. 

 

0 REPLIES 0