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

Pradeep Thipani
Mega Sage

Hi @Dhanu1 ,

 

1. how to Make a relation between Change request and catalog Task:

To relate the Change Request to the Catalog Task, you can create a reference field in the sc_task table to store the sys_id of the associated Change Request.


2.  catalog t
ask should be closed once Change is closed: You can write a Business rule to make it happen when ever change is closed to close the catalog task.


3. how to add worknotes in change request ex.. 

  1. Created from Task.: You can add a work note when creating the Change Request from the catalog task to indicate its source. This can be done in the same UI Action where the Change Request is created.

Let me know if you have any questions on the above. 

 

Please mark my answer as correct/helpful if applicable.

 

 

Thanks,

Pradeep

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep

Dhanu1
Tera Contributor

Hi Pradeep, Thank for your reply.

2.  catalog task should be closed once Change is closed: You can write a Business rule to make it happen when ever change is closed to close the catalog task. - If possible you have any similar script ?



3. how to add worknotes in change request ex.. 

  1. Created from Task.: You can add a work note when creating the Change Request from the catalog task to indicate its source. This can be done in the same UI Action where the Change Request is created.      i wrote script as shown below , it is working for incident but for change it is not working, kindly help me on this

    (function(current, previous, gs, action) {
        var changeRequest = ChangeRequest.newNormal();
        changeRequest.setValue("short_description", current.short_description);
        changeRequest.setValue("description", current.description);
        //changeRequest.setValue("cmdb_ci", current.u_configuration.u_configuration_item);
        changeRequest.setValue("cmdb_ci", current.cmdb_ci);
        //changeRequest.setValue("u_configuration", current.u_configuration);
        // changeRequest.setValue("category", current.category);
        // changeRequest.setValue("u_sub_category", current.subcategory);
        changeRequest.setValue("requested_by", current.request.requested_for);
        changeRequest.setValue("assignment_group", current.assignment_group);
        changeRequest.setValue("u_regional_group", current.u_regional_group);
        changeRequest.setValue("parent", current.sys_id);
        changeRequest.setValue("work_notes", current.getValue("number"));
        //changeRequest.work_notes = "Converted from " + " " + current.number;
     
    Thank you



 

 

Dhanu1
Tera Contributor

Hello Team,

Any one please guide me on the attached After business rule.

Dhanu1_0-1726653862804.png

var sctask = new GlideRecord('sc_task');
sctask.addQuery('change_request',current.sys_id);
sctask.query();
while(sctask.next()) {
    sctask.state = 3;
    sctask.setWorkflow(false);
    sctask.update();
}

Hi @Dhanu1 ,

 

Give a try with below script,

 

// Check if the change request is closed
if (current.state == 3) {
// Query the catalog tasks related to this change request
var catTaskGR = new GlideRecord('sc_task');
catTaskGR.addQuery('change_request', current.sys_id);
catTaskGR.addQuery('state', '!=', 3); // Check if the catalog task is not already closed
catTaskGR.query();

while (catTaskGR.next()) {
// Set the catalog task state to Closed
catTaskGR.state = 3;
catTaskGR.update();
}
}

 

Please mark my answer as correct/helpful if applicable.

 

 

Thanks,

Pradeep

 

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep