Update the incident Work notes

Sakshi Lambat
Tera Contributor

Update the incident work notes and changes the state to back to Work in progress of the incident when the Change Request is created from Incident. How to achieve this?

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Sakshi Lambat 

You can create a Before Update business rule like the one below on Incident table.

 

AnveshKumarM_0-1701691414933.png

AnveshKumarM_1-1701691445491.png

 

AnveshKumarM_2-1701691460007.png

 

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

	current.work_notes = "Change " + current.getDisplayValue('rfc') + ' create from this incident.';
	current.state = 2;

})(current, previous);

 

Please mark my answer helpful and accept as a solution if it helped šŸ‘āœ”ļø

Thanks,
Anvesh

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Sakshi Lambat 

so what script did you try so far and what's not working?

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

Hi

 

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

 

    // Check if the change is created from an incident

    if (current.incident && current.incident != '') {

        var incidentGR = new GlideRecord('incident');

        if (incidentGR.get(current.incident)) {

            

            // Update work notes

            incidentGR.work_notes = 'Change created: ' + current.number;

            incidentGR.update();

 

            // Change incident state back to "Work in Progress"

            incidentGR.state = 2; // Assuming 2 represents "Work in Progress" 

            incidentGR.update();

        }

    }

 

})(current, previous);

 

I tried this BR but not working

 

@Sakshi Lambat 

The above BR is written as After/Before and on which table

small update in script -> don't use update() 2 times

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


// Check if the change is created from an incident

if (current.incident && current.incident != '') {

var incidentGR = new GlideRecord('incident');

if (incidentGR.get(current.incident)) {


// Update work notes

incidentGR.work_notes = 'Change created: ' + current.number;


// Change incident state back to "Work in Progress"

incidentGR.state = 2; // Assuming 2 represents "Work in Progress"

incidentGR.update();

}

}

 

})(current, previous);

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

AnveshKumar M
Tera Sage
Tera Sage

Hi @Sakshi Lambat 

You can create a Before Update business rule like the one below on Incident table.

 

AnveshKumarM_0-1701691414933.png

AnveshKumarM_1-1701691445491.png

 

AnveshKumarM_2-1701691460007.png

 

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

	current.work_notes = "Change " + current.getDisplayValue('rfc') + ' create from this incident.';
	current.state = 2;

})(current, previous);

 

Please mark my answer helpful and accept as a solution if it helped šŸ‘āœ”ļø

Thanks,
Anvesh