- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 11:24 AM
The requirement is to auto-generate the creation of Release Phase when a Release Record is submitted.
Please see the screenshot of the Business rule I created.
However, instead of inserting one record only it inserts 134 records.
Please help. Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 12:39 PM
There are another/other out of box Business Rule(s) running when a Release record is created. Add a line to prevent them from running when this Business Rule runs, then only one Release Phase record will be created.
(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord('rm_release_phase');
rec.initialize();
rec.short_description = current.short_description;
rec.parent = current.sys_id;
rec.setWorkflow(false);
rec.insert();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 04:03 AM
Hello @tindiz ,
By observing all the details and information shared by you, It seems like the issue is related to preventing other business rules from running and ensuring the proper creation of records in the desired sequence.
To address this, you can modify the business rules to manage the flow of record creation. Below is a suggested solution:
Business Rule on rm_release (After Insert):
(function executeRule(current, previous /*null when async*/) {
// Your existing code to create Release Phase record
var recPhase = new GlideRecord('rm_release_phase');
recPhase.initialize();
recPhase.short_description = current.short_description;
recPhase.parent = current.sys_id;
recPhase.setWorkflow(false);
recPhase.insert();
// Your existing code to create Release Task record
var recTask = new GlideRecord('rm_task');
recTask.initialize();
recTask.parent = recPhase.sys_id; // Linking to Release Phase
recTask.short_description = "Communications Plan";
recTask.insert();
})(current, previous);
Business Rule on rm_release_phase (After Insert):
(function executeRule(current, previous /*null when async*/) {
// Your existing code to create Release Task record
var recTask = new GlideRecord('rm_task');
recTask.initialize();
recTask.parent = current.sys_id; // Linking to Release Phase
recTask.short_description = "Communications Plan";
recTask.insert();
})(current, previous);
With this modification, the business rules are organized in a way that ensures the Release Phase is created first, and then the Release Task is created under the Release Phase.
The setWorkflow(false) is used to prevent any recursive business rules from running, which might be causing the issue of multiple records being inserted.
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
AnikeT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 12:39 PM
There are another/other out of box Business Rule(s) running when a Release record is created. Add a line to prevent them from running when this Business Rule runs, then only one Release Phase record will be created.
(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord('rm_release_phase');
rec.initialize();
rec.short_description = current.short_description;
rec.parent = current.sys_id;
rec.setWorkflow(false);
rec.insert();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 10:06 PM
Hi @Brad Bowman it worked! However, my other Business rule did not work this time. From the Release record after it gets submitted a Release Phase should generate (which already worked with the script you provided) and then Release Task should be generated under Release Phase but my below BR did not work this time for Release Task creation. Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 10:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 04:03 AM
Hello @tindiz ,
By observing all the details and information shared by you, It seems like the issue is related to preventing other business rules from running and ensuring the proper creation of records in the desired sequence.
To address this, you can modify the business rules to manage the flow of record creation. Below is a suggested solution:
Business Rule on rm_release (After Insert):
(function executeRule(current, previous /*null when async*/) {
// Your existing code to create Release Phase record
var recPhase = new GlideRecord('rm_release_phase');
recPhase.initialize();
recPhase.short_description = current.short_description;
recPhase.parent = current.sys_id;
recPhase.setWorkflow(false);
recPhase.insert();
// Your existing code to create Release Task record
var recTask = new GlideRecord('rm_task');
recTask.initialize();
recTask.parent = recPhase.sys_id; // Linking to Release Phase
recTask.short_description = "Communications Plan";
recTask.insert();
})(current, previous);
Business Rule on rm_release_phase (After Insert):
(function executeRule(current, previous /*null when async*/) {
// Your existing code to create Release Task record
var recTask = new GlideRecord('rm_task');
recTask.initialize();
recTask.parent = current.sys_id; // Linking to Release Phase
recTask.short_description = "Communications Plan";
recTask.insert();
})(current, previous);
With this modification, the business rules are organized in a way that ensures the Release Phase is created first, and then the Release Task is created under the Release Phase.
The setWorkflow(false) is used to prevent any recursive business rules from running, which might be causing the issue of multiple records being inserted.
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
AnikeT