Inserir botão de aprovação no e-mail

Anselmo Cruz Ma
Kilo Expert

Bom dia, é possível adicionar um botão de aprovação na notificação enviada por e-mail?

1 ACCEPTED SOLUTION

carlosbertaso
ServiceNow Employee
ServiceNow Employee

Anselmo,

 

Você pode utilizar como exemplo o email script incident_take_me_to_the_incident que toda instancia tem onde é criado um botão para levar o usuário ao incidente ele possui um botão com cor, bordas arredondadas e etc e ajustar o email padrão de notificação para apresentar algo em um formato mais agradável.

 

 

incident_take_me_to_the_incident 

https://xxxxxxx.service-now.com/nav_to.do?uri=sys_script_email.do?sys_id=f25bc270d711120035ae23c7ce610323

 

Catalog Approval Request

https://xxxxx.service-now.com/nav_to.do?uri=sysevent_email_action.do?sys_id=927afd45c0a8010a001f28267acf98e4%26sysparm_view=advanced

 

Anexei duas imagens a do padrão de aprovação onde temos as palavras link e o exemplo do script que existe para um incidente.

 

 

 

View solution in original post

6 REPLIES 6

gabrielterra
Giga Contributor

Bom dia Anselmo,

Existe uma inbound action (Update Approval Request) ootb que faz exatamente isso que você quer. Procure pela inbound action na tabela sysevent_in_email_action.

 

Abaixo seguem alguns links sobre essa funcionalidade:

https://docs.servicenow.com/bundle/madrid-servicenow-platform/page/administer/service-administration...

https://docs.servicenow.com/bundle/madrid-servicenow-platform/page/administer/notification/concept/c...

 

 

Muito obrigado, @gabrielterra.

rafaelramos
ServiceNow Employee
ServiceNow Employee

Oi!

O que eu já fiz anteriormente foi a criação de um Script E-Mail que exibe um botão de "Aprovar" e "Rejeitar" para as aprovações de Requested Itens, exibindo as variáveis e detalhes.

O que o botão faz é abrir um email de resposta (usando o mailto, abre um novo email no client email utilizado pelo usuário) a ser enviada para a plataforma.

Outra maneira seria direcionar o usuário diretamente para o registro de aprovação (isso inclusive é nativo com um link).

 

Abaixo o Script E-Mail

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
var link = gs.getProperty('glide.servlet.uri') + "sp?id=approval&table=" + current.getTableName() + "&sys_id=" + current.getUniqueValue();
var approval = link;
var arr = [];
arr.push(current.sysapproval.sys_class_name.getDisplayValue());
arr.push(current.sysapproval);
var str = current.document_id.number+' - '+gs.getMessage( 'Approval Request');
var str2 = current.document_id+' '+current.document_id.u_requested_for.getDisplayValue();
email.setSubject(str);

template.print('<p><font size="4" color="#808080" face="helvetica"><strong>' + gs.getMessage('Request Details') + '</strong></font></p>');
template.print('<p><font size="3" color="#808080" face="helvetica">' + gs.getMessage('Short Description') + ': ' + gs.getMessage('${sysapproval.short_description}') + '</font></p>');
template.print('<p><font size="3" color="#808080" face="helvetica">' + gs.getMessage('Requested for') + ': ' + gs.getMessage('${document_id.u_requested_for}') + '</font></p>');
template.print('<p><font size="3" color="#808080" face="helvetica">' + gs.getMessage('Requested By') + ': ' + gs.getMessage('${sysapproval.opened_by}') + '</font></p>');

template.print('<p><font size="3" color="#808080" face="helvetica">' + gs.getMessage('Summary of Requested item') + ': </font></p>');
var item = new GlideRecord("sc_req_item");
item.addQuery("sys_id", current.document_id);
item.query();
while(item.next()) {
//template.print(item.number + item.cat_item.getDisplayValue());
template.print('<BR>');
//+ ": " + item.quantity + " X " + item.cat_item.getDisplayValue() + " at " + item.price.getDisplayValue() + " each \n");
//template.print(" Opções:\n");
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(item.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
template.space(4);
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
template.print('<BR>');
}
}
}

template.print('<font face="helvetica">');
template.print('</font>');
template.print(' ');

var backgroundColor = 'background-color: #278efc;';
var backgroundColorblue = 'background-color: #4a81be;';
var backgroundColorred = 'background-color: #be0000;';
var border = 'border: 1px solid #0368d4;';
var color = 'color: #ffffff;';
var colorgreen = 'color: #ADFF2F;';
var coloryellow = 'color: #FFD700;';
var fontSize = 'font-size: 16px;';
var fontFamily = 'font-family: Helvetica, Arial, sans-serif;';
var textDecoration = 'text-decoration: none; border-radius: 3px;';
var webKitBorder = '-webkit-border-radius: 3px;';
var mozBorder = '-moz-border-radius: 3px;';
var display = 'display: inline-block;';
var padding = 'padding: 5px;';

template.print('<BR>');
template.print('<font face="helvetica">');
template.print(renderMailtoButton('Aprovar'));
template.print(' style="' + backgroundColorblue + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print('<img style="vertical-align:middle; cursor: pointer;" title="Aprovar" src="thumbup.png" alt="" width="46" height="45" />Aprovar');
template.print('</a>');
template.print('</font>');
template.print(' ');
template.print('<font face="helvetica">');
template.print(renderMailtoButton('Rejeitar'));
template.print(' style="' + backgroundColorred + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print('<img style="vertical-align:middle; cursor: pointer;" title="Rejeitar" src="thumbdown.png" alt="" width="46" height="45" />Rejeitar');
template.print('</a>');
template.print('</font>');
template.print('<br><br>');

template.print('<BR>');
template.print('<font face="helvetica">');
template.print('<a href="' + approval + '"');
template.print('style="' + backgroundColor + border + color + fontSize + fontFamily + textDecoration + webKitBorder + mozBorder + display + padding);
template.print('">');
template.print(gs.getMessage('Click here to view Approval Request'));
template.print('</a>');
template.print('</font>');
template.print('<br><br>');

})(current, template, email, email_action, event);

 

Criação da Inclusão de Script (Script Include) - renderMailtoButton

function renderMailtoButton(response){

var emailAddress = 'test@test.com';
var mark = email.watermark;
var number = current.number;
//Different number if from an approval
if (current.getTableName().indexOf("sysapproval") != -1){
number = current.sysapproval.number;
}

var backgroundColor = 'background-color: #278efc;';
var border = 'border: 1px solid #0368d4;';
var color = 'color: #ffffff;';
if (response == "Aprovar")
color = 'color: #ADFF2F;';
if (response == "Rejeitar")
color = 'color: #FFD700;';
var fontSize = 'font-size: 16px;';
var fontFamily = 'font-family: Helvetica, Arial, sans-serif;';
var textDecoration = 'text-decoration: none; border-radius: 3px;';
var webKitBorder = '-webkit-border-radius: 3px;';
var mozBorder = '-moz-border-radius: 3px;';
var display = 'display: inline-block;';
var padding = 'padding: 5px;';
var mailLinkpart1 = '<a href="mailto:'+ emailAddress + '?subject= Re:' + number + ' - ' + response +' [MENSAGEM CRIADA AUTOMATICAMENTE - CLIQUE EM ENVIAR]&body=Comentários para sua ação de '+response+'.%0A%0A[Se precisar, utilize esse espaço para seus comentários]%0A%0A---------- Uso reservado do sistema, favor não alterar ----------%0A%0A' + mark + '"';
return mailLinkpart1;
}

 

Fica faltando aqui a "Ação de Entrada" (Inbond Actions) para processar o email de resposta enviado para a plataforma.

Muito obrigado, @rafaelramos