business rule creating duplicate record in original table

walshy
Giga Expert

Ok so I have a business rule that does what it should, it creates a new song record in a 'set list' table. 

However the rule then generates a duplicate in the 'songs list', so I have 2 of the same song in the 'songs list' table. 

find_real_file.png

So below is the 'when to run'

find_real_file.png

And here is the script. I was thinking it was because of insert being ticked, but I thought that was if a record was inserted on the table, not insert a new record when this rule is run. 

(function executeRule(current, previous /*null when async*/) {
	
	var gr = new GlideRecord("x_120100_band_set_lists");
	
	gr.initialize();
	
	gr.u_song_title=current.u_song_title;  //Song Title
	gr.u_lead_vocals=current.u_lead_vocals;  //Lead vocals
	gr.u_kylie_key=current.u_kylie_key;  //Our key
	gr.u_genre=current.u_genre;  //Song Genre
	gr.u_original_artist=current.u_original_artist; //Original artist
	
	
	gr.insert();
	
})(current, previous);

I figure this is pretty simple, Im just being a bit of a nong and missing something. 

It shouldn't add a new record to the 'song list' table just to the 'set list'

 

1 ACCEPTED SOLUTION

Hi Nikhil,

You were right, the issue wasn't the script. 

The issue was me extending the songs table to create the set list table. 

I created new set list tables and the duplication is gone. 

View solution in original post

6 REPLIES 6

Nikhil Pandit
Mega Guru

Hi

The script loooks good, I think this is happening because of update checkbox. Pl try to debug it.

Hi Nikhil,

You were right, the issue wasn't the script. 

The issue was me extending the songs table to create the set list table. 

I created new set list tables and the duplication is gone. 

SaiRaviKiran Ak
Giga Guru

Hi,

 

Change the When to run condition to After insert or update  and try.

Thanks,

Ravi

manoj6699
Giga Contributor

Hi Walshy,

Uncheck the insert checkbox, use only update option and which will fix the issue.

 

Thanks,

Manoj.