Problem

Anantha27
Mega Guru

When creating a problem ticket if the urgency and impact are high, I need to generate automatic ptask with some fields to auto populate and then the ticket should be created 

7 REPLIES 7

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi @Anantha27 ,
You can write a onAfter business rule on problem table with condition if the urgency and impact are high and it should run on Insert only and in script you can use GlideRecord API to create the problem_task.


 

 


Thanks and Regards,

Saurabh Gupta

Deepak Negi
Mega Sage
Mega Sage

Use Flow Designer for this.

It is easier to do and you dont have to write any code.

 

DeepakNegi_0-1730787221492.png

 

 

Thanks

Deepak

VishaalRanS
Tera Guru

Hi @Anantha27 

To automate the creation of a problem ticket in ServiceNow when both urgency and impact are set to high, you can utilize business rules and script actions. Example:

  • Define the Conditions with Urgency and Impact fields are set to high.
  • Create a Business Rule for problem table with
  • Condition: current.urgency == '1' && current.impact == '1' ​
  • Define a Script for Creating the PTask:
(function executeRule(current, previous /*null when async*/) {
    // Create a new PTask record
    var ptask = new GlideRecord('ptask'); // Replace 'ptask' with the actual table name for PTask
    ptask.initialize();
    
    // Populate fields with desired values
    ptask.short_description = 'PTask for Problem: ' + current.number;
    ptask.problem = current.sys_id; // Link to the created problem ticket
    ptask.state = 'New'; // Set initial state as New
    
    // Add any additional fields you want to auto-populate
    ptask.assigned_to = current.assigned_to; // Example: Assign to the same user as the problem ticket
    
    // Insert the PTask record into the database
    ptask.insert();
    
})(current, previous);

 

  • Ensure that your user roles have permission to create records in both the Problem and PTask tables.

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

NikhilKamlekar
Tera Expert

Hi @Anantha27 ,

 

You can create After Insert BR with below Condition & Script to create a Problem Task if the Problem is created with Urgency & Impact is high:

NikhilKamlekar_0-1730786123255.pngNikhilKamlekar_1-1730786143758.pngNikhilKamlekar_2-1730786190186.png

NikhilKamlekar_3-1730786218168.pngNikhilKamlekar_4-1730786248339.png

Script:

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

    // Add your code here
    var pTask = new GlideRecord('problem_task');
    pTask.initialize();
    pTask.short_description = current.short_description;
    pTask.insert();
    gs.addInfoMessage('Problem Task created for Incident with high impact and urgency');
})(current, previous);
If it's helpful, kindly mark it has helpful and accept the solution. So, that it will helpful for others