Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Priyanka136
Mega Guru

Hi walshy,

Try this :- Write Before - insert Business Rule & Use current.setAbortAction(true); in your code

Please mark it Correct or Helpful, if it works based on impact....!!!!

Warm Regards,

Priyanka

find_real_file.png

www.dxsherpa.com

walshy
Giga Expert

Thanks for all the suggestions. 

I think I have screwed up with the table set up. 

I extended the 'songs list' table when I created the 'set lists' table to avoid making the tables again. I think every time I add to the set list table, it is adding another song to the songs list due to the extension? 

Or am I just making stuff up?