MIM Workbench adding counter to the Status Update communication mail being sent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 01:38 AM
Hello Team,
I need help with below requirement please help with the same.
Add a counter to the Workbench emails for MIM.
Communication is getting stored in "incident_alert_task" in the table comm_plan.source stores the incident number which was upgraded to Major Incident.
There are four kind of communication being sent to "Initial" , "Status Update", "Resolution" "Ad hoc"
I need to attain below requirement and update the field “Communication count” on “incident_alert_task” table, I need to do this all in the mail script so that
it can be called in my mail body.
How can I do it in ServiceNow??
Initial Communication : Number will always be 1, only one such communication is sent.
Status updates: Count should start at 2, if second communication is getting sent then it should be 3 and so on..
Below is the logic written by me as apart of email script
(function runMailScript(current, template, email, email_action, event) {
// These are string values (not references)
var sourceIncident = current.comm_plan.source.number;//INC123456
var shortDesc = current.comm_plan.source.short_description;// This is for testing MIM Workbench
var taskType = current.comm_task_definition.name; // Initial MIM Communication, Status Update(rest 2 are there which I don't need)
var commCount = 1; // Default for Initial MIM Communication(as OOB comm_count is set to 1 once the Initial MIM Communication is being sent and its one time)
if (taskType === 'Status Update') {
var gr = new GlideRecord('incident_alert_task');
gr.addQuery('comm_plan.source.number', sourceIncident); // Compare incident number string
gr.addQuery('comm_task_definition.name', 'Status Update'); // Only Status Updates
gr.addQuery('sys_id', '<', current.sys_id); // Earlier status updates only
gr.query();
var previousStatusUpdates = 0;
while (gr.next()) {
previousStatusUpdates++;
}
// 1 for Initial MIM + earlier + current
commCount = 1 + previousStatusUpdates + 1;
}
var emailLine = "MIM com #" + commCount + " - Major Incident " + sourceIncident + " - " + shortDesc;
template.print(emailLine);
})(current, template, email, email_action, event);
so my need is the status update first coom_count should begin with 2 ( 1 for Initial MIM Communication + first status update communication being sent by the user)
But the above code is only setting the comm count to " MIM com #1 - Major Incident INC5022483 - Test", its not doing any addition or its not managing the incremental counter it 2, 3, ,4 if further communication is being sent, how can we do so.
Thanks.