When a user clicks on the Communicate workaround UI action on the Problem form:
Let's try to understand what things gets executed by the ServiceNow system, when user click on the Communicate workaround UI action Form Link on the Problem record form layout. Before we even discuss that, please note that Communicate workaround button or form link will only appear if Workaround field is not empty in current Problem record. Secondly, Duplicate Of field, which can reference another Problem record, should be empty.
Communicate workaround UI action click
Okay, now we understood, how Communicate workaround UI Action will appear to user on Problem record form. Now let's see what happens if Communicate workaround button is clicked. As per out of box code version of this UI Action, it shows that ServiceNow first updates the two fields on Problem record record viz. workaround_communicated_at and workaround_communicated_by fields with current date time value and logged in user id respectively.
function onCommunicateWorkaround() {
if (g_form.modified) {
getMessage("You have unsaved changes. Please save them
to continue", function(msg) {
g_form.addErrorMessage(msg);
});
return false;
}
g_form.submit('communicate_workaround_new'); } if (typeof window == "undefined") communicateWorkaround(current); function
communicateWorkaround(current) {
action.setRedirectURL(current);
var time = new GlideDateTime();
current.workaround_communicated_at = time;
current.workaround_communicated_by = gs.getUserID();
current.update();
gs.eventQueue('communicate.workaround', current, current.workaround);
gs.addInfoMessage(gs.getMessage('Workaround communicated')); } |
Simultaneously, system triggers an event named communicate.workaround. The event communicate.workaround triggers execution of two Script Action viz. "Copy Prb workaround to Inc comments" and "Copy Prb workaround to Inc work notes". These script actions update JournalEntry fields Comments and Work Notes respectively on Incident records mapped to the current Problem record.
Script Action: Copy Prb workaround to Inc work notes
This update those incident wherein state is not Resolved which means Incident are Active. System updates the Incident Work Notes fields with concatenated value of current Problem Number and Workaround details entered in Problem record.
var work_notes = "[code]" + event.parm1 + "[/code]"; var incident = new GlideRecord('incident'); incident.addQuery('problem_id', current.getUniqueValue()); incident.addQuery("incident_state", '<', IncidentState.RESOLVED); incident.query(); while(incident.next()) {
incident.work_notes.setJournalEntry(current.number + ' ' + work_notes);
incident.update(); } |
Script Action: Copy Prb workaround to Inc comments
Similar to above logic of Incident Work Notes, this script action updates Incident Comments on filtered Incidents wherein state is Resolved and Close Codes populated.
var CLOSE_CODE_KNOWN_ERROR = "Known error"; var comments = "[code]" + event.parm1 + "[/code]"; var incident = new GlideRecord('incident'); incident.addQuery('problem_id', current.getUniqueValue()); incident.addQuery('state', IncidentState.RESOLVED); incident.addQuery('close_code', CLOSE_CODE_KNOWN_ERROR); incident.query(); while (incident.next()) {
incident.comments.setJournalEntry(current.getDisplayValue() + ' ' + comments);
incident.update(); } |
As conclusion, we can say, when a user clicks on the Communicate workaround UI action on the Problem form, system updates mapped open Incident Work Notes and Closed Incident Comments field
No comments:
Post a Comment