How to generate an additional comment in a Task through workflow?

Reinaldo Vieira
Tera Contributor

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:

 

ReinaldoVieira_0-1735587968863.png

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();

 

8 REPLIES 8

BriTaylor
Kilo Sage

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?

Brad Bowman
Kilo Patron
Kilo Patron

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;

 

@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?

 

ReinaldoVieira_0-1735832591280.png

 

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);