- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 09:10 AM
Hi
I have an ask to create a parent Case as soon as a case has been created and make the relationship by updating parent filed.
For that I created the following BR
Async / Insert
var parentCase = new GliderRecord ('case');
parentCase.initialize();
var parentSysID = parentCase.insert();
current.parent = parentSysID;
current.update();
I have used all the below statements but the BR keeps on running and creating more records
current.setWorkflow(false)
parentCase.setWorkflow(false)
current.setAbortionAction(true);
parent.Case.setAbortionAction(true);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 02:52 PM
Assuming table "Task" has field "Created from":
then business rule 1:
- Table = sn_customerservice_case
- When = after
- Insert = true
- Filter Conditions = [ Created from ] [ is empty ]
- Script =
(function executeRule (current) {
var parent = new GlideRecord('sn_customerservice_case');
parent.newRecord();
parent.u_created_from = current.getUniqueValue();
// Maybe also copy other fields
parent.insert();
})(current);
business rule 2:
- Table = sn_customerservice_case
- When = after
- Insert = true
- Filter Conditions = [ Created from ] [ is not empty ]
- Script =
(function executeRule (current) {
var child = current.u_created_from.getRefRecord();
if (child && child.isValidRecord() && isCase(child)) {
child.parent = current.getUniqueValue();
child.update();
}
function isCase (child) {
return child.getRecordClassName() == current.getRecordClassName();
}
})(current);
The result is:
Pictures of the BRs attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 02:10 PM
Giga
Thank you so much for your response
If you have time, could you write a bit of the code as an example? It will help me visualize it
Many thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2023 02:52 PM
Assuming table "Task" has field "Created from":
then business rule 1:
- Table = sn_customerservice_case
- When = after
- Insert = true
- Filter Conditions = [ Created from ] [ is empty ]
- Script =
(function executeRule (current) {
var parent = new GlideRecord('sn_customerservice_case');
parent.newRecord();
parent.u_created_from = current.getUniqueValue();
// Maybe also copy other fields
parent.insert();
})(current);
business rule 2:
- Table = sn_customerservice_case
- When = after
- Insert = true
- Filter Conditions = [ Created from ] [ is not empty ]
- Script =
(function executeRule (current) {
var child = current.u_created_from.getRefRecord();
if (child && child.isValidRecord() && isCase(child)) {
child.parent = current.getUniqueValue();
child.update();
}
function isCase (child) {
return child.getRecordClassName() == current.getRecordClassName();
}
})(current);
The result is:
Pictures of the BRs attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 05:52 AM
That is a great job... thank you so much !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2023 06:38 AM
You're welcome 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 11:17 AM
remove current.update();
quote from the developer portal:
Do not use current.update() in a Business Rule script. The update() method triggers Business Rules to run on the same table for insert and update operations, potentially leading to a Business Rule calling itself over and over.
read more here: https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/business_rules_technica...