How to show comments of RITM on request?

BijoyDeb
Tera Contributor

Hi all,

   I have a requirement where if  a user posts additional comments for RITM record, then description field on the request record (sc_request) should get updated with same value.

What should be best approach for this and please help me with script as well

Thanks in advance

1 ACCEPTED SOLUTION

Karthiga S
Kilo Sage

Hi @BijoyDeb 


Sure, you can achieve this by creating a Business Rule in ServiceNow. Here are the steps:

 

1. Navigate to System Definition > Business Rules.
2. Click on New to create a new Business Rule.
3. Give it a meaningful name, for example, "Update Request Description".
4. Select the table as "Requested Item [sc_req_item]".
5. In the "When to run" section, select "After" and "Inserts/Updates".
6. In the "Filter Conditions" section, add a condition to check if the "Additional Comments" field has changed. You can use the changes() function for this.
7. In the "Script" section, write a script to update the description field of the associated request record. Here is a sample script:

(function executeRule(current, previous /*null when async*/) {
// Get the associated request record
var request = new GlideRecord('sc_request');
if (request.get(current.request)) {
// Update the description field
request.description = current.comments.getJournalEntry(1);
// Update the record without triggering Business Rules
request.setWorkflow(false);
request.update();
}
})(current, previous);


This script gets the most recent journal entry from the "Additional Comments" field and updates the "Description" field of the associated request record.

Also, this script updates the record without triggering other Business Rules. If you want to trigger other Business Rules, you can remove the setWorkflow(false) line.

 

Please mark it Correct and Hit Like if you find this helpful!

 

Regards,

Karthiga

 

View solution in original post

2 REPLIES 2

Karthiga S
Kilo Sage

Hi @BijoyDeb 


Sure, you can achieve this by creating a Business Rule in ServiceNow. Here are the steps:

 

1. Navigate to System Definition > Business Rules.
2. Click on New to create a new Business Rule.
3. Give it a meaningful name, for example, "Update Request Description".
4. Select the table as "Requested Item [sc_req_item]".
5. In the "When to run" section, select "After" and "Inserts/Updates".
6. In the "Filter Conditions" section, add a condition to check if the "Additional Comments" field has changed. You can use the changes() function for this.
7. In the "Script" section, write a script to update the description field of the associated request record. Here is a sample script:

(function executeRule(current, previous /*null when async*/) {
// Get the associated request record
var request = new GlideRecord('sc_request');
if (request.get(current.request)) {
// Update the description field
request.description = current.comments.getJournalEntry(1);
// Update the record without triggering Business Rules
request.setWorkflow(false);
request.update();
}
})(current, previous);


This script gets the most recent journal entry from the "Additional Comments" field and updates the "Description" field of the associated request record.

Also, this script updates the record without triggering other Business Rules. If you want to trigger other Business Rules, you can remove the setWorkflow(false) line.

 

Please mark it Correct and Hit Like if you find this helpful!

 

Regards,

Karthiga

 

BijoyDeb
Tera Contributor

Thanks @Karthiga S , it worked as i expected!