- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:27 PM
Hi all,
I am writing an after insert/update business rule on a table (u_example) that is creating a record on another table (u_budget_key). This business rule is running only when my field, Budget Key is empty.
(function executeRule(current, previous /*null when async*/) {
var key = new GlideRecord('u_budget_key');
key.initialize();
key.u_gl = current.u_gl;
key.u_vendor = current.u_vendor;
key.u_cc = current.u_cc;
key.insert();
})(current, previous);
The script is working, but instead of only inserting one record, there are 2 duplicate records added to the other table. Can anyone help me diagnose why?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:59 PM
Great to know it worked.
Also, what I meant was condition not necessarily has to be the same check if there is something that runs on update & when it runs for the record which it runs for has Budget Key empty or not.
In addition you could also check below once that runs after insert/update
(function executeRule(current, previous /*null when async*/) {
var key = new GlideRecord('u_budget_key');
key.addQuery('u_gl',current.u_gl);
key.addQuery('u_vendor',current.u_vendor);
key.addQuery('u_cc',current.u_cc);
key.query();
if(!key.next()) //if not then insert
{
key.initialize();
key.u_gl = current.u_gl;
key.u_vendor = current.u_vendor;
key.u_cc = current.u_cc;
key.insert();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:44 PM
Hi Jaspal,
There are no other business rules that run on the same table with that condition. I was able to get it to work from what Ben sent. Thanks anyways!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:59 PM
Great to know it worked.
Also, what I meant was condition not necessarily has to be the same check if there is something that runs on update & when it runs for the record which it runs for has Budget Key empty or not.
In addition you could also check below once that runs after insert/update
(function executeRule(current, previous /*null when async*/) {
var key = new GlideRecord('u_budget_key');
key.addQuery('u_gl',current.u_gl);
key.addQuery('u_vendor',current.u_vendor);
key.addQuery('u_cc',current.u_cc);
key.query();
if(!key.next()) //if not then insert
{
key.initialize();
key.u_gl = current.u_gl;
key.u_vendor = current.u_vendor;
key.u_cc = current.u_cc;
key.insert();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 01:02 PM
Jaspal,
This worked, thanks a ton!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:56 PM
Hi Jaspal,
This is actually still outstanding, I thought that I had solved it. The solve that Ben came up with actually populates the Budget Key field. I want to have this field remain empty.
There are no other business rules running on the same table with the condition Budget Key | is empty

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 12:34 PM
Do this need to run on both insert and update? I think the "on update" is causing it to trigger a second time. You could add key.setWorkflow(false); before the insert and see if that helps!
Hope this helps!
If this was helpful or correct, please be kind and click appropriately!
Michael Jones - Proud member of the CloudPires Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!