We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Move PTask created in the Problem Ticket to Work in Progress state

kamblepooja
Tera Contributor

I want to move all the PTask created in the Problem Ticket to Work in Progress state once the Problem Ticket was approved by the Problem Approver - Fix in progress state.

6 REPLIES 6

Nilesh Pol
Kilo Sage

@kamblepooja To achieve this, you can use a AFTER business rule to automatically update the state of all PTasks associated with a Problem Ticket once the Problem Ticket is approved and moves to the "Fix in Progress" state. Here's a step-by-step guide on how you can set this up:

navigate to Business rule->New.

Give the proper name, and select problem table.

checked the advanced checkbox.

when to run: Set after, to ensure the BR runs after the problem is updated.

condition: current.state == 'Fix in Progress' && current.previous.state != 'Fix in Progress'

Script:

(function executeRule(current, previous /*null when async*/) {
var pTaskGR = new GlideRecord('task'); // Assuming PTasks are stored in the 'task' table
pTaskGR.addQuery('problem_id', current.sys_id); // Link PTasks to the current Problem Ticket
pTaskGR.addQuery('state', '!=', 'Work in Progress'); // Only update tasks not already in 'Work in Progress'
pTaskGR.query();

while (pTaskGR.next()) {
pTaskGR.state = 'Work in Progress'; // Set the state to 'Work in Progress'
pTaskGR.update();
}
})(current, previous);

 

Save the business rule and ensure it is activated.

 

This business rule will automatically update the state of all PTasks associated with a Problem Ticket to "Work in Progress" once the Problem Ticket is approved and moves to the "Fix in Progress" state.

BhavaniYamsani
Giga Contributor

Hi @kamblepooja ,

Create a BR

Table: problem
When: after
Insert: false
Update: true
Delete: false
Advanced: true

Condition:
State changes to Fix in Progress

script:

// Run only when Problem moves to Fix in Progress
if (current.state.changesTo(3)) { // 3 = Fix in Progress (verify in your instance)

var ptaskGR = new GlideRecord('problem_task');
ptaskGR.addQuery('problem', current.sys_id);
ptaskGR.addQuery('state', '!=', 2); // 2 = Work in Progress
ptaskGR.query();

while (ptaskGR.next()) {
ptaskGR.state = 2; // Work in Progress
ptaskGR.update();
}
}

Please mark as helpful if this gives you the answer. 

Thanks
Yamsani Bhavani
ServiceNow Developer

Ankur Bawiskar
Tera Patron

@kamblepooja 

so what did you start with and where are you stuck?

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

Hi @Ankur Bawiskar ,
There is a workflow for this and we need to modify that flow as per the requirement. Please see the attach Snipet below:
Could you please guide as per the requirement where should we do the necessary changes and what changes required.

kamblepooja_0-1770732665339.png