Business rules

Ram012
Tera Contributor

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.

4 REPLIES 4

Krushna R Birla
Kilo Sage

@Ram012 Can you share your code, will try to help you out. Thanks

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.

OlaN
Giga Sage
Giga Sage

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?

BillMartin
Mega Sage

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