Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

To update additional comments when ritm is created for particular catalog item in servicenow

Jay N
Tera Contributor

Hi Expert,

 

We have a requirement to update worknotes/comments on RITM when a RITM is created for a particular set of catalog items, can any one please help me with the code.

 

Thanks,

Dhanunjay

5 REPLIES 5

kaushal_snow
Giga Sage

Hi @Jay N ,

 

Create an After Insert Business Rule on the sc_req_item (RITM) table, filter to your desired catalog items (using their sys_id values). Inside the script, set current.work_notes (and current.comments if needed), then call current.update()...

 

(function executeRule(current, previous /* null on insert */) {
  
  var itemIds = ['Catalog Item Sys_id', 'fedcba0987654321fedcba0987654321'];
  if (itemIds.indexOf(current.cat_item.toString()) === -1) {
    return;
  }

  current.work_notes = 'RITM created for Catalog Item "' 
                       + current.cat_item.getDisplayValue() + '"';
  
  current.comments = 'Info added for item at ' + new GlideDateTime();

  current.update();
})(current, previous);

 

Give it  try once, and let me know..

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

There is a diff way as well, using Flow designer...............

 

Trigger: “When a record is created” Table = Requested Item [sc_req_item]

Condition: catalog_item is one of [your items]

Action: Update Record

Record type: Requested Item

Value: Work notes = Custom text pill


** Ensure that you check the “Update journal field” box in the flow action UI.

 

Try any one of these and it will work..

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

DGAJ
Giga Guru

Hi @Jay N ,

You can use the UI Policy approach which won't require any coding-

After insert UI policy on the sc_req_item table , condition> item(cat_item) is item 1 OR item(cat_item) is item2.

On the actions tab , select comment field set to your desired comments.

 

If you still want the code options for BR -

(function executeRule(current, previous /*null when async*/) {
    var relevantCatalogItems = ['item_sys_id_1', 'item_sys_id_2']; // Replace with actual sys_ids
// you can also store the sys_ids of the catalog item in a sys_property and retrieve it

    if (relevantCatalogItems.indexOf(current.cat_item.toString()) > -1) {
        current.work_notes = 'Your worknotes to add.';
        current.comments = 'Your comment to add.';
        current.update();
    }
})(current, previous);

 

*******************************************************************************************
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards,
DJ

DGAJ

UI Policies are for form control, not script execution.