Árvore de páginas

Versões comparadas

Chave

  • Esta linha foi adicionada.
  • Esta linha foi removida.
  • A formatação mudou.

...

By using scripts in processes, it is possible to you can manipulate values of the related form, communicate with external services, send emails to external people, manipulate attachments of the request, handle request attachments and publish in the Documents, resource, query datasets, add validations in to the movement transaction of the request, integrate with other requests or other points of the platform, generate logs, etc.

...

Painel
borderColor#ebecf0

Estado
subtletrue
titleEXAMPLE OF USE

In a Supplier Payment process, there is a need to send an email notification to a person from the supplier company when the payment is made and the request is finalized. Since this person is from another company, they are not a participant in the process and do not have a registration on the platform, making it impossible to notify them through the notification settings available in the End component.

In this case, it is possible to you can add a script for the afterProcessFinish event. Thus, when you finalize the request is finalized, the person from the supplier company will be aware that their payment has been made, as they will also receive the notification email.

Bloco de código
languagejs
titleafterProcessFinish
function afterProcessFinish(processId) {
    try {
        var remetente = "MATRICULA_DO_REMETENTE";
        //The code of the email template previously registered in
        //"Control Panel > Email Templates"
        var templateEmail = "CODIGO_TEMPLATE_EMAIL";
        var parametros = new java.util.HashMap();         
        //Parameter that will be used as the subject of the email
        parametros.put("subject", "Seu pagamento foi realizado");
        //Template parameter that will receive the name of the person in charge contained in
        //the "responsavelFornecedor" field of the form
        parametros.put("NOME_RESPONSAVEL", hAPI.getCardValue("responsavelFornecedor"));
        //Template parameter that will receive the amount paid and that is contained in
        //the "valorPago" field of the form
        parametros.put("VALOR_PAGAMENTO", hAPI.getCardValue("valorPago"));
        //Instantiates the list of recipients
        var destinatarios = new java.util.ArrayList();
        //Adds the external email of the person in charge of the supplier of the request
        //that is contained in the "emailFornecedor" field of the form
        destinatarios.add(hAPI.getCardValue("emailFornecedor"));
       //Sends the email
       notifier.notify(remetente, templateEmail, parametros, destinatarios, "text/html");
    } catch(e) {
        log.error("Error sending email to the supplier: " + e);
    }
}

...

01. With the process in edit mode, click on the  Script tab– located in the middle of the top bar.

02. On the left side, see all the process events that have scripts.

03. Click on each event to view its script.

Painel
borderColor#f2f2f2
bgColor#f2f2f2

To hide the list of events, click on Close . To view the list again, simply click on Open.


Add script to the process

...

01. With the process in edit mode, click on the the Script tab– located in the middle of the top bar.

02. On the left side, click on Add script– located at the top.

03. Select the process event for which you want to add a script.

04. Click on Add.

05. In the coding area, enter the script code that should be executed must run when the selected event occurs in the process.

06. Click on Save draft – located on the right side of the top bar – to save the created script.

07. In the displayed message, click on Ok, I understand.


Edit process script

...

01. With the process in edit mode, click on the the Script tab– located in the middle of the top bar.

02. On the left side, locate and click on the event for which you want to edit the script.

03. In the coding area, edit the script code that should be executed must run when the selected event occurs in the process.

04. Click on Save draft – located on the right side of the top bar – to save the changes made to the script.

05. In the displayed message, click on Ok, I understand.


Delete process script

...

01. With the process in edit mode, click on the the Script tab– located in the middle of the top bar.

02. On the left side, locate the event from which you want to delete the script.

03. Click on Delete.

04. Click on Save draft – located on the right side of the top bar – to save the process considering the deletion of the scriptscript deletion process.

05. In the displayed message, click on Ok, I understand.


Informações
titleAttention!

This documentation is valid from the   Voyager update (2.0) update onwards. If you are using a previous update, it may contain information different from what you see on your platform.



HTML
<!-- Hotjar Tracking Code for http://tdn.totvs.com/display/fb -->
<script>
    (function(h,o,t,j,a,r){
        h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
        h._hjSettings={hjid:1280165,hjsv:6};
        a=o.getElementsByTagName('head')[0];
        r=o.createElement('script');r.async=1;
        r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
        a.appendChild(r);
    })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>