Business rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 11:25 PM
Create two fields description field in CustomTable1 and CustomTable2 table. When you create a CustomTable1 record the description from corresponding CustomTable2 record should get populated ?
Writing Business rule code but not working.
Any idea above scenaior.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 11:32 PM
@Ram012 Can you share your code, will try to help you out. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 11:40 PM
Table: CustomTable1
Field: Description (text field)
Trigger: On Create of CustomTable1 record
// Condition: None (always execute)
Action:
1. Get the corresponding CustomTable2 record
2. Copy the Description field value from CustomTable2 to CustomTable1
// Code:
function AutoPopulateDescription() {
// Get the current CustomTable1 record
var customTable1Record = GetRecord('CustomTable1');
// Get the corresponding CustomTable2 record (assuming a relationship exists)
var customTable2Record = GetRelatedRecord('CustomTable2', customTable1Record);
// Copy the Description field value from CustomTable2 to CustomTable1
customTable1Record.setDescription(customTable2Record.getDescription());
// Save the updated CustomTable1 record
SaveRecord(customTable1Record);
}
How to map two custom tables any idea.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2024 11:45 PM
Hi,
That shouldn't be that hard (without knowing any of the details of your setup).
Basically you write a business rule that runs on after insert/update of record in Customtable1, and set conditions that the description of the record changes (and that corresponding record in Customtable2 exists).
Then in the scripting section of the BR, retrieve the corresponding record in Customtable2, and set it's description value from the current record.
What's the issue you are facing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2024 12:51 AM
Hi Amar,
I suggest you create your code inside scripts include, then just instantiate in the correct ServiceNow object. We normally recommend using Flow Designer instead of business rules.
Create an Action so it can be a reusable function using the GlideDBUtil.createElement