Duplicate tickets creating with same ticket number

Hari S1
Tera Contributor

Hi,

 

We have updated inbound script with the working code (script given below), surprisingly servicenow creating two incidents with the same incident number. Not sure how can this be possible to have the same incident tickets in service now. Here attached screenshot of tickets which got created twice every time we receive Inbound email.

 

HariS1_0-1671823328530.png

 



First incident shown in image suppose to be correct one bebcause inboud email received with some subject. But second incident pointned in image not suppose to be created, even then it has no subject in it.

Could you please point to me if there is anything wrong with script.

 

			(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {


				var res = email.subject.split("] [");

				assignment_group_pick = res[1];//group

				if (assignment_group_pick == "DB group") {
					current.assignment_group.setDisplayValue("DB group1");
				} 
				else {
					current.assignment_group.setDisplayValue("DB group2");
				}

				res_reg_loc = res[2].split('|');
				res_reg = res_reg_loc[0].trim();
				if (res_reg == "region") {
					current.u_region = "KR";
				} else {
					current.u_region = res_reg;
				}

				
				var location = res_reg_loc[1].trim();
				current.location.setDisplayValue(location);


				

				
				var res_ci_in = email.subject;
				var reg_loc = "|" + location + "]";
				var after_loc_split = res_ci_in.split(reg_loc);
				var res_test = after_loc_split[1].trim();

				var regex_check = res_test.match(/\[(.*?)\].*/);

				var ci_complete_name = regex_check[1].trim();

				var ci = new GlideRecord('cmdb_ci');
				ci.addQuery('name', ci_complete_name);
				ci.query();
				if (ci.next()) {
				   
					current.cmdb_ci.setDisplayValue(ci_complete_name);
					
				} else {


					char_look_for_sub = '.::]:: ';
					char_look_for = char_look_for_sub.split("::");
					start_char_pos = 0;
					end_char_pos = 0;

				var res_ci_in1 = email.subject;

				var res_ci = res_ci_in1.split(reg_loc)[1];

				var ci_sub_str_char = res_ci.substr(2, res_ci.length);

				var i = 0;

				for (i = 0; i < ci_sub_str_char.length; i++) {
					if ((ci_sub_str_char[i] == char_look_for[0]) || (ci_sub_str_char[i] == char_look_for[1]) || (ci_sub_str_char[i] == char_look_for[2])) {
						end_char_pos = i;
						break;
					}
				}
				var ci2 = ci_sub_str_char.substr(start_char_pos, end_char_pos);
				current.cmdb_ci.setDisplayValue(ci2);
				}

				current.insert();



		})(current, event, email, logger, classifier);

 

 

 

1 REPLY 1

Subrahmanyam2
Giga Guru

Hi Hari,

 

It might be because of other before insert business rules or scripts that execute on server side (may be workflows or flows even if they are configured). 
Since current.insert() returns sys_id of newly inserted record. You can log it and see which incident is correct one to be sure.
Validate if any of your before insert business rules or workflows have current.insert() statement in them which can cause duplicate insertion.


Thanks and regards,

Subrahmanyam