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

Ankur Bawiskar
Tera Patron
Tera Patron

@Reinaldo Vieira 

you are running that script even before creating those tasks

you should be having that script in the advanced script section in each of those Catalog Tasks activities

Something like this in each catalog task advanced script

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" + current.request.getDisplayValue()
            "\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.getDisplayValue()
            "\n- O processo tem um SLA total de até 30 dias para ser finalizado" +
            "\n" + current.request.getDisplayValue()
            "\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;

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Reinaldo Vieira 

if you face any challenge in getting catalog task number then check this link

How to access the catalog task number within the Workflow Activity creating the task? 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Reinaldo Vieira 

you can also use before insert BR on sc_task with below condition

current.request_item.cat_item.name == 'Your Catalog Item Name Here'

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    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" + current.request.getDisplayValue()
    "\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.getDisplayValue()
    "\n- O processo tem um SLA total de até 30 dias para ser finalizado" +
    "\n" + current.request.getDisplayValue()
    "\n A tarefa " + current.number + " foi criada e agora está em análise técnica e funcional o Gestor Técnico apontado no formulário";
    current.comments = msg;

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Reinaldo Vieira 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader