How to prevent Business Rule from inserting duplicate user records on related list?

DP10
Tera Contributor

Can anyone let me know how I can have my after update business rule stop inserting duplicate records into my related list? I just need one record in the related list per user. Here is my business rule: 

 

 

 And here is the issue. This is the related list (duplicates appeared for the other two users as well but I deleted them):

 

I have a scheduled job that updates "Last reminded" and a few other fields. I run the scheduled job after the Business Rule inserts a record. The job updates the fields it needs to update but then the BR inserts the same user again. How can I stop this from happening?

1 ACCEPTED SOLUTION

//See  the extra filter in the user exists check

function insertUser(sys_id) 
{
	var gdt = new GlideDateTime(current.trips_return_date);
	gdt.addDaysLocalTime(10);
	
	//Query if there is already a user for this scc with this due date.
	var grUser = new GlideRecord('x_g_dnf3_fedsim_scc_ref_list');
	grUser.addQuery('user', current.trips_user);
	grUser.addQuery('sample', sys_id);
	grUser.addQuery('due_date', gdt.getDate()); //check due date
	grUser.query();
	
	//insert only if there is not one already
	if(!grUser.next()){
		var grUserNew = new GlideRecord('x_g_dnf3_fedsim_scc_ref_list');
		grUserNew.initialize();
		grUserNew.user = current.trips_user;
		grUserNew.sample = sys_id;
		grUserNew.due_date = gdt.getDate();
		grUserNew.insert();
	}        
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

9 REPLIES 9

DP10
Tera Contributor
For your if statement can I do if(!grUser.next && !due_date)?

That is not a valid stmt.

 

What do you want to check with due date?

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

DP10
Tera Contributor
I would want current.user AND due_date not to match

//See  the extra filter in the user exists check

function insertUser(sys_id) 
{
	var gdt = new GlideDateTime(current.trips_return_date);
	gdt.addDaysLocalTime(10);
	
	//Query if there is already a user for this scc with this due date.
	var grUser = new GlideRecord('x_g_dnf3_fedsim_scc_ref_list');
	grUser.addQuery('user', current.trips_user);
	grUser.addQuery('sample', sys_id);
	grUser.addQuery('due_date', gdt.getDate()); //check due date
	grUser.query();
	
	//insert only if there is not one already
	if(!grUser.next()){
		var grUserNew = new GlideRecord('x_g_dnf3_fedsim_scc_ref_list');
		grUserNew.initialize();
		grUserNew.user = current.trips_user;
		grUserNew.sample = sys_id;
		grUserNew.due_date = gdt.getDate();
		grUserNew.insert();
	}        
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

DP10
Tera Contributor

Works like a charm on first try. Thanks for the idea. Big help