Send email with only newly added attachment for Network assignment group incidents

GaneshErike
Tera Expert

Hi Team,

 

I have a requirement to send an email notification when a new attachment is added to an Incident, but only for incidents assigned to the Network assignment group.

 

The email must include only the newly added attachment.

Previously attached / older attachments should NOT be included in the email.

 

Thanks in advance.

8 REPLIES 8

Olá @GaneshErike ,

Sim, a orientação do @Ankur Bawiskar  é perfeita! A abordagem dele de usar o script de Condição Avançada dentro da Notificação é mais elegante do que criar um Evento separado.

No entanto, em relação ao seu problema com o anexo aparecendo como sys_attachmentmetadados de tabela em vez do arquivo propriamente dito:

O motivo técnico: a caixa de seleção "Incluir anexos" tenta encontrar arquivos anexados ao registro de destino. Como o registro de destino É o anexo ( sys_attachment), ela não consegue encontrar o conteúdo do arquivo porque um arquivo não pode ser anexado a si mesmo dessa maneira.

A solução (o código para corrigir o anexo): Você pode usar a lógica de filtro do @Ankur Bawiskar , mas para anexar o arquivo ao e-mail, você precisa de uma regra de negócios na tabela de e-mail .

Crie esta regra de negócio:

  • Tabela: E-mail [ sys_email]

  • Quando: Antes de (Inserir)

  • Condição: A tabela alvo Ésys_attachment

Roteiro:

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

    // This creates the bridge between the Email and the Physical File
    var grEmailAtt = new GlideRecord('sys_email_attachment');
    grEmailAtt.initialize();
    grEmailAtt.email = current.sys_id;
    grEmailAtt.attachment = current.instance; // 'instance' holds the SysID of the attachment record
    grEmailAtt.insert();

})(current, previous);

Resumo:

  1. Utilize o script do Ankur para a Condição de Notificação (para filtrar por grupo de Rede).

  2. Utilize esta regra de negócio para forçar o arquivo a ser anexado corretamente ao e-mail de saída.

Se essa solução combinada funcionar para você, marque a resposta do Ankur e a minha como Útil/Aceita.

Atenciosamente,
Brandão.

Ankur Bawiskar
Tera Patron

@GaneshErike 

Things to do

-> create notification on sys_attachment table with Insert checkbox and use advanced notification condition to check the INC group and then only send by setting answer=true/false

answer = false;

var incRec = new GlideRecord('incident');
if (incRec.get(current.table_sys_id)) {
    if (incRec.assignment_group.getDisplayValue() == 'Network Support') {
        answer = true;
    }
}

AnkurBawiskar_0-1770557618113.png

 

-> then use this link below where I shared approach to include latest attachment in the email

Adding latest attachment from sys_attachment table to sys_email record 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

@GaneshErike 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Mariuisd
Tera Contributor

Ganesh, standard notifications include all attachments. To send only the new one, create an async business rule on sys_attachment for Network incidents, trigger a custom event, and use a mail script in the notification to include just the new file. Multiple uploads will trigger multiple emails.