How to generate an additional comment in a Task through workflow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:47 AM
Good afternoon, everyone.
I'm working on a workflow related to the creation of Catalog Tasks in a specific Catalog Item and I need to write a Script that would generate additional comments in each task, as the evolving on the RITM work.
Could you please help me on this? Also need to know how to catch the REQnumber related (maybe through a GlideRecord)
Please find attached a screenshot of the current workflow and one of its scripts:
function updateAdditionalComments() {
var grTask = new GlideRecord('sc_task');
grTask.addEncodedQuery('active=true^request_item=' + current.getValue('sys_id'));
grTask.orderBy('sys_updated_on');
grTask.setLimit(1);
grTask.query();
while (grTask.next()) {
var msg = "";
msg = "Olá, aqui se inicia o processo de homologação de software, algumas informações importantes:" +
"\n- Para acompanhamento do processo, utilize o É Comigo Tecnologia, toda a comunicação será feita através do chamado" + [REQnumber]
"\n- Fique atento em seu e-mail, o ServiceNow dispara um e-mail para sua caixa de entrada a cada atualização no chamado" + [REQnumber]
"\n- O processo tem um SLA total de até 30 dias para ser finalizado" +
"\n" +
"\n A tarefa " + grTask.number.getDisplayValue() + " foi criada e agora está em análise técnica e funcional o Gestor Técnico apontado no formulário";
grTask.comments = msg;
grTask.update();
}
}
updateAdditionalComments();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 12:55 PM
Hello,
You should be able to get the REQnumber by using "grTask.request_item".
Also is there a reason you are using Workflows instead of flow designer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 01:00 PM
You can get the REQ number in this script using:
current.request.number
The problem with the circled script is that it looks like it runs before any of the Catalog Tasks have been created. You can either run this (again) after the last Catalog Task activity, removing the setLimit line and active=true from the encoded query to update all of the tasks, or try adding to each Catalog Task activity in the Advanced script field:
var msg = "Olá, aqui se inicia o processo de homologação de software, algumas informações importantes:" +
"\n- Para acompanhamento do processo, utilize o É Comigo Tecnologia, toda a comunicação será feita através do chamado" + current.request.number +
"\n- Fique atento em seu e-mail, o ServiceNow dispara um e-mail para sua caixa de entrada a cada atualização no chamado" + current.request.number +
"\n- O processo tem um SLA total de até 30 dias para ser finalizado" +
"\n" +
"\n A tarefa " + task.number + " foi criada e agora está em análise técnica e funcional o Gestor Técnico apontado no formulário";
task.comments = msg;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 07:43 AM
@Brad Bowman the code worked to get the REQ number, but didn't get the task number when generating the comment
Is there any other way to get the task number?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 09:25 AM
The script in the Catalog Task activity runs as/before the task record is created, so I wasn't sure if that part would work. The best approach may be a separate Run Script activity after each Catalog Task activity similar to your original grTask GlideRecord. You can orderByDesc sys_created_on to get the correct task to update, or in the Catalog Task activity script you can use a line like
workflow.scratchpad.tsknumber = task.number;
then use
grTask.addEncodedQuery('number=' + workflow.scratchpad.tsknumber);