Business Rule to update custom Release field on Task with Requested Item Related List field Release

Siddharth Parna
Tera Contributor

Hi 

I am working on a business rule to Update custom field(Release- created by me on Task Table) to update with Task Related Request Item Related List field Product Release.

I want to make sure that once Release is linked with RITM,then Product Release  value is updated on RITM and then with business rule make to update custom Release field value on Task.

I tried writing the business rule but unable to achieve the automation .

This is the business rule I am using

(function executeRule(current, previous /*null when async*/ ) {

    var reqItem = new GlideRecord('sc_req_item');
    if (reqItem.get(current.request_item)) {
        var rel = new GlideRecord('rm_release');
        rel.addQuery('u_ritm', reqItem.sys_id); //Unable to fetch the relation here in place of u_ritm
        rel.query;
        if (rel.next()) {
            current.u_release = rel.u_release; // u_release is new release record value created on task
  }

    }

})(current, previous);

 

Product Release.PNG
     
5 REPLIES 5

Swapna Abburi
Mega Sage
Mega Sage

Hi @Siddharth Parna 

I think you should write the business rule on 'rm_release' table. Then query task table using ritm reference in rm_release table and update the custom field.

Ankur Bawiskar
Tera Patron
Tera Patron

@Siddharth Parna 

your business rule is on which table? I assume it's sc_task

update as this and see

(function executeRule(current, previous /*null when async*/) {
    // Ensure the task is linked to an RITM
    if (!current.request_item) {
        return;
    }

    // Fetch the related RITM
    var ritm = new GlideRecord('sc_req_item');
    if (ritm.get(current.request_item)) {
        // Assuming the RITM has a reference field 'u_product_release' to Product Release
        if (ritm.u_product_release) {
            // Set the Task's Release field to the Product Release value from RITM
            current.u_release = ritm.u_product_release;
            current.update();
        }
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur ! 

I see Product release in related list of RITM, but I am unable to get the reference field on RITM.When I check RITM table I don't see Product release in the table.As I have shared screenshot I could see Product Releases in RITM 

@Siddharth Parna 

is it a defined relationship?

If yes then on Product release table there must not be any field which refers to RITM

Share the complete related list screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader