How to close catalog task after change request state is closed ?

Dhanu1
Tera Contributor

Hi Team,

Good Day,

I created Normal change Request from the catalog task by using UI Action , Now i have three requirements

1. how to Make relation between Change request and catalog Task.
2.  catalog t
ask should be closed once Change is closed.
3. how to add worknotes in change request ex.. 

  1. Created from Task.


    Thank You.
5 REPLIES 5

Vaishnavi Lathk
Mega Sage
Mega Sage

 

To implement your requirements for linking a Normal Change Request to a Catalog Task in ServiceNow, follow these steps:

1. Create a Relationship Between Change Request and Catalog Task

You can create a reference from the Catalog Task to the Change Request by updating the Catalog Task record when you create the Change Request. Here’s how to do it in a UI Action:

 

// UI Action Script
function createChangeRequest() {
    var changeRequest = new GlideRecord('change_request');
    changeRequest.initialize();
    changeRequest.short_description = 'Change created from Catalog Task';
    // Set other required fields
    changeRequest.insert();

    // Assuming `current` is the Catalog Task record
    current.change_request = changeRequest.sys_id; // Create reference
    current.update();
}

 

2. Automatically Close Catalog Task When Change is Closed

You can use a Business Rule to automatically close the Catalog Task when the associated Change Request is closed. Here’s a sample Business Rule:

  • Table: change_request
  • When: After
  • Condition: current.state.changesTo('closed') (or however you define "closed")

Script:

 

 
// Business Rule Script
if (current.change_request) {
    var catalogTask = new GlideRecord('sc_task');
    if (catalogTask.get(current.change_request)) {
        catalogTask.state = 'closed'; // Set to Closed state
        catalogTask.update();
    }
}
 

3. Add Worknotes to the Change Request

You can add work notes to the Change Request from the Catalog Task using a script. Here's an example you can include in your UI Action or Business Rule:

 

// Adding work notes to the Change Request
if (current.change_request) {
    var changeRequest = new GlideRecord('change_request');
    if (changeRequest.get(current.change_request)) {
        changeRequest.work_notes = 'Created from Task.';
        changeRequest.update();
    }
}

Summary of Implementation

  1. Link Change Request and Catalog Task: Use a UI Action to create a Change Request and store the reference in the Catalog Task.
  2. Close Catalog Task on Change Closure: Set up a Business Rule to close the Catalog Task when the Change Request is closed.
  3. Add Worknotes: Update the Change Request with work notes when necessary.

These implementations will help establish a robust relationship between your Change Requests and Catalog Tasks. Let me know if you need further clarification or assistance!