I am getting "Unique Key violation" "Duplicate entry" error. How to fix that?

Vaishnavi35
Tera Guru

Hi,

 

Vaishnavi35_0-1718217414272.png

 

I am getting this error when I click on "Accept" button on Idea form. 

How to fix this?

 

Thanks,

Vaishnavi

 

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron
Kilo Patron

Hi @Vaishnavi35 , 

Based on shared log details, there is insert query running over task table which is adding program record, and the sys_id showing in the unique key voilation belongs to one of PGM record.

Please check the code without this PGM record code, comment that part and test it again. It should work.

 

-Thanks,

AshishKM

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

17 REPLIES 17

Zach Koch
Giga Sage
Giga Sage

This link may help you. This isn't the exact field listed in the KB, but the idea and issue happening is most likely the same. KB Article 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

I did not understand the article. what is it trying to achieve?

 

James Chun
Kilo Patron

Hi @Vaishnavi35,

 

It looks like you are creating another record with the same sys_id.

Do you mind sharing the script of the Accept UI Action?

Also do you have any Business Rule that is doing either current.update or current.insert?

 

Cheers

 

Hi James,

Here is the Accept UI Action script and condition.

Vaishnavi35_0-1718307659574.png

 

I have two BR's that are creating Demand and RITM,  when Idea is accepted.

To create Demand,

var demandTable = "dmn_demand";
if(GlidePluginManager.isActive('com.snc.project_management_v3')){
	demandTable = SNC.PPMConfig.getDemandTable(current.getTableName());
}

var demand = new GlideRecord(demandTable);
demand.setValue("description", current.description);

demand.setValue("requested_by", current.u_required_completion_date_if_any);//requested_by
//demand.setValue("u_glide_date_2", current.u_required_completion_date_if_any);

//demand.setValue("portfolio", current.u_global_process_shared_services_area);
 if (current.u_global_process_shared_services_area) {
     demand.setValue("portfolio", current.u_global_process_shared_services_area); // This should work if field is populated
 }

if (current.portfolio) {
    demand.setValue("portfolio", current.portfolio); // This should work if field is populated
}

//demand.setValue("portfolio", current.portfolio);
demand.setValue("primary_program",current.u_program);
demand.setValue("priority", current.priority);

demand.setValue("short_description", current.short_description);
//demand.setValue("category","strategic");
demand.setValue("type", "project");
demand.setValue("submitter", current.submitter);
demand.setValue("parent", current.sys_id);
demand.setValue("idea", current.sys_id);
var dmnId = demand.insert();
demand.get(dmnId);
current.demand = dmnId;
current.stage = 'demand';
GlideSysAttachment.copy('idea', current.sys_id, 'dmn_demand', demand.sys_id);
var link = ' <a href ="/' + demandTable + '.do?sysparm_query=number%3D' + demand.getValue('number') + '">'+ demand.getValue('number') +'</a>';
var message = gs.getMessage("Demand {0} has been created");
message = message.replace("{0}", link);
gs.addInfoMessage(message);

 

To create RITM,

createRequest();
function createRequest() {
var cart = new Cart();   //calling the cart API
var item = cart.addItem('389e052687e20e909e70c91acebb351f');   //sys_id of the catalog item I want to fire
cart.setVariable(item, 'u_project_name', current.short_description); //sets catalog variable to the email's subject
cart.setVariable(item, 'u_project_description', current.description);
cart.setVariable(item, 'u_cost_center_c', current.u_cost_center);
cart.setVariable(item, 'u_portfolio_c', current.portfolio);
cart.setVariable(item, 'u_program_c', current.u_program);
cart.setVariable(item, 'u_requested_for', current.u_requested_for);
cart.setVariable(item, 'u_request_made_by', current.submitter); 
cart.setVariable(item, 'u_manager', current.u_requested_for.manager); 
cart.setVariable(item, 'u_demand_number', current.demand.number); 
var rc = cart.placeOrder();   //this launches the catalog item, and creates a request object.   rc = the request object
updateRITM(rc.sys_id);   //call a function immediately to update the ritm.   This must be a nested function, otherwise inbound actions get weird.

           //also, we're passing the sys_id of the request so we know what RITM to grab.
}
function updateRITM(req){
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', req);   //req is what we passed from the previous function. the sys_id of the request.
ritm.query();
while (ritm.next()){
ritm.u_requested_for = current.u_requested_for;   //my ritm table separately tracks its own customer, since I don't use Request
//ritm.description = email.body_text;   //we're still in the inbound action so why not exploit?
       //ritm.priority = email.body.priority;     //good example of how to exploit email body variables
       ritm.update();
}

 

If you can help?

 

Thanks,

Vaishnavi