Fields to be passed from problem to incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 10:04 PM
Fields to be passed from problem to incident.
whenever the mentioned problem fields are updated, we need to copy them in the worknotes of related incident if the incident state is 'On hold' and on hold reason is 'Pending problem'
Please see the below screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 10:29 PM
Hi @VaishakP1978942 ,
You can write after business rule and use below script.
(function executeRule(current, previous /*null when async*/) {
// List of fields to monitor for updates
var fieldsToMonitor = ['short_description', 'description', 'close_notes']; // Add your specific fields here
// Check if monitored fields are updated
var updatedFields = [];
fieldsToMonitor.forEach(function(field) {
if (current[field] != previous[field]) {
updatedFields.push(field);
}
});
// If no monitored fields are updated, exit
if (updatedFields.length === 0) {
return;
}
// Construct the message to add to the worknotes
var worknotesMessage = 'The following fields were updated in the related Problem:\n';
updatedFields.forEach(function(field) {
worknotesMessage += field + ': ' + current[field] + '\n';
});
// Find related Incidents in 'On Hold' state with reason 'Pending Problem'
var grIncident = new GlideRecord('incident');
grIncident.addQuery('problem_id', current.sys_id); // Related to this problem
grIncident.addQuery('state', 3); // 'On Hold' state
grIncident.addQuery('hold_reason', '3'); // 'Pending problem' hold reason
grIncident.query();
// Update worknotes for each related Incident
while (grIncident.next()) {
grIncident.work_notes = worknotesMessage;
grIncident.update();
}
})(current, previous);
Also you can add when to run condition with your target column.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 11:02 PM
Have after update BR on problem and use this
Something like this but please enhance it as per your requirement for extra fields. I just added for 2 fields
var incidentRec = new GlideRecord('incident');
incidentRec.addQuery('problem_id', current.getUniqueValue());
incidentRec.addQuery('state', 3);
incidentRec.addQuery('hold_reason', 'Pending Problem'); // give the correct choice value here
incidentRec.query();
if (incidentRec.next()) {
incidentRec.work_notes = 'Workaround: ' + current.work_around + ' Close notes: ' + current.close_notes;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 11:11 PM
you can also use Flow designer for this with no code solution
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2024 08:41 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader