When incident task is attached to incident make u_open_incident_task to true

rmishra4395
Tera Contributor

Hello Team,

 

I need help here ASAP

 

I have created one custom field called as u_open_incident_task field on incident table. so whenever incident task is attached to the incident then make u_open_incident_task to true.

 

 

3 REPLIES 3

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @rmishra4395 - What's the use case? You could create a business rule on incident_task...after insert, when Incident is not empty, update the incident referenced in 'incident'.

Bert_c1
Kilo Patron

@rmishra4395 

You can use a business rule, as mentioned above, that runs on the incident_task table. Defined as shown below

Screenshot 2024-11-19 141744.png

And the script in the Advanced tab:

 

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

	// Add your code here
	// Update the incident field u_open_incident_task
	var inc = new GlideRecord('incident');
	inc.addQuery('sys_id', current.incident.toString());
	inc.query();
	if (inc.next()) {
		inc.u_open_incident_task = 'true';
		inc.update();
	}

})(current, previous);

 

Alternatively, the following would be a bit more efficient:

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

    // Retrieve the referenced incident record
    var inc = current.incident.getRefRecord();

    if (inc.isValidRecord()) {
        // Check if the field is not already true
        if (inc.u_open_incident_task !== true) {
            inc.u_open_incident_task = true; // Use Boolean value directly
            inc.update();
        }
    }

})(current, previous);