Incident State Update Error

DipinVasu
Tera Contributor
*** Script: Valid field
FAILED TRYING TO EXECUTE ON CONNECTION glide.2 (connpid=30439): INSERT INTO task (`made_sla`,`upon_reject`,`sys_updated_on`,`a_int_6`,`a_int_1`,`sys_class_name`,`task_effective_number`,`number`,`sys_id`,`sys_updated_by`,`a_int_2`,`opened_by`,`urgency`,`sys_created_on`,`sys_domain`,`company`,`state`,`reassignment_count`,`sys_created_by`,`knowledge`,`a_int_3`,`approval`,`impact`,`sys_mod_count`,`active`,`a_int_7`,`priority`,`sys_domain_path`,`opened_at`,`a_str_12`,`a_str_8`,`escalation`,`upon_approval`,`a_ref_4`,`a_str_1`) VALUES(1,'cancel','2024-07-02 07:09:31',0,1,'incident','INC0010087','INC0010087','c120c34783874e105e175030ceaad378','admin',3,'6816f79cc0a8016401c5a33be04be441',6,'2024-07-02 07:09:31','global',NULL,3,0,'admin',0,3,'not requested',6,0,1,0,5,'/','2024-07-02 05:17:18','CLI000101','GLCP1002001',0,'proceed','c520c34783874e105e175030ceaad341','inquiry') /* dev255479001, gs:BF37C883830B0E105E175030CEAAD3C5, tx:70d997c383874e105e175030ceaad3f1 */ Unique Key violation detected by database ((conn=30439) Duplicate entry 'c120c34783874e105e175030ceaad378' for key 'PRIMARY') : java.sql.SQLIntegrityConstraintViolationException: (conn=30439) Duplicate entry 'c120c34783874e105e175030ceaad378' for key 'PRIMARY':

I am trying to update status of incident table state field , but i am getting above error 


Script Include :

var GLCPUpdateIncidentStatus = Class.create();
GLCPUpdateIncidentStatus.prototype = {
    initialize: function() {
    },

    resolveIncident: function(incidentId) {
        var gr = new GlideRecord('incident');
        if (gr.get(incidentId)) {
            if (gr.isValidField('state')) {
                gs.info('Valid field');
                gr.setValue('state', '3'); // Ensure you use setValue for updating fields
                gr.update(); // Update the record
                gs.info("Incident " + incidentId + " resolved.");
                return true; // Return success
            } else {
                gs.info("incident_state field not valid or accessible.");
                return false; // Return failure
            }
        } else {
            gs.info("Incident " + incidentId + " not found.");
            return false; // Return failure
        }
    },

    type: 'GLCPUpdateIncidentStatus'
};

 

4 REPLIES 4

Sujatha V M
Kilo Patron
Kilo Patron

@DipinVasu  Please refer the below support case, 

 

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

 

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

 

Please mark this as helpful and accept it as a solution if this resolves your query.

Thanks,

Sujatha V.M.

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Satishkumar B
Giga Sage
Giga Sage

Hi @DipinVasu 

try this:

 

 

var GLCPUpdateIncidentStatus = Class.create();
GLCPUpdateIncidentStatus.prototype = {
    initialize: function() {
    },

    resolveIncident: function(incidentId) {
        var gr = new GlideRecord('incident');
        if (gr.get(incidentId)) { // Retrieves the incident record by sys_id
            if (gr.isValidField('state')) { // Checks if 'state' is a valid field
                gs.info('Valid field');
                gr.setValue('state', '3'); // Sets the state to '3' (Resolved state)
                gr.update(); // Commits the update to the database
                gs.info("Incident " + incidentId + " resolved.");
                return true; // Returns true indicating success
            } else {
                gs.info("state field not valid or accessible.");
                return false; // Returns false if 'state' field is not valid or accessible
            }
        } else {
            gs.info("Incident " + incidentId + " not found.");
            return false; // Returns false if incident with given sys_id is not found
        }
    },

    type: 'GLCPUpdateIncidentStatus'
};

 

 

 

  • Ensure that 'state' field in the incident table allows updating with the value '3'.
  • Check if there are any business rules, client scripts, or other processes that might be interfering with your script's execution.


-----------------------------------------------------------------------------------

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

 

 

James Chun
Kilo Patron

Hi @DipinVasu,

 

Where are you invoking the Script Include from? A Business Rule?

Can you share its configuration as well?

 

Cheers

kaduapoorva
Tera Contributor

Hello @DipinVasu ,

 

Please try below one for your error,

var gr = new GlideRecord('incident'); gr.addQuery('number', 'INC0010087'); // Example incident number gr.query(); if (gr.next()) { gr.state = '2'; // Example state value (2 for In Progress, for instance) gr.update(); }

 

Please mark helpful if it solves your issue