CA Service Management

Expand all | Collapse all

WF approval button

  • 1.  WF approval button

    Posted Sep 15, 2016 11:19 AM

    Hello guys,

     

    To approve a Classic Workflow, the approver has to click on Edit and change the status to Approve or reject.

     

    Is there a way to have buttons called 'Approve', 'Reject' instead which will perform these tasks?

    I create these buttons yet, but I don't know how to configure the function to change the status of detail_cr_wf.

     

    <PDM_MACRO name=button Caption="Approve" Func="zApproval('APP')" hotkey_name="[A]" ID="bntapp">

    <PDM_MACRO name=button Caption="Reject" Func="zApproval('REJ')" hotkey_name="[R]" ID="bntrej">

     

    Any idea guys?

     

    Thanks.

     



  • 2.  Re: WF approval button

    Posted Sep 15, 2016 07:20 PM

    Take a look at the order_change_approval.htmpl form, it has a js function you might be able to repurpose that does what you're after. 



  • 3.  Re: WF approval button

    Posted Sep 16, 2016 09:39 AM

    Thanks for the information.

    At this moment, i'm trying to customize the function to allow the button to update the workflow task status.

     

    This is the code I'm trying to change, but didn't work.. I don't know what I need to do.. =(

     

     

    <PDM_MACRO name=button Caption="Aprovar tarefa" Func="approve_reject('APP')" hotkey_name="[A]" ID="bntapp">

     

     

     

    function approve_reject(status) {
    //check if status change for the task is possible.
    if("$args.status.allow_task_update" == "1" || "$args.status.code" == "PEND")
    {
    var temp_persid = "0";
    var frm = document.forms["frmDTLRO"];
    var prev_persid_pointer = cur_persid_pointer;
    var comments = document.getElementsByName("SET.comments")[0].value;
    temp_persid = persid_array[cur_persid_pointer];
    if(cur_persid_pointer<persid_arr_len-1) {
    cur_persid_pointer = cur_persid_pointer + 1;
    }
    cur_persid = persid_array[cur_persid_pointer];
    if(cur_persid!='' && temp_persid!='0') {
    if(status!='' && status!=undefined){
    frm.elements["NEXT_PERSID"].value = cur_persid;
    frm.elements["PERSID"].value = temp_persid;
    frm.elements["NEW_STATUS"].value = status;
    frm.elements["COMMENTS"].value = comments;
    frm.elements["PREV_POINTER"].value = prev_persid_pointer;
    frm.elements["KEEP.PERSID_POINTER"].value = cur_persid_pointer;
    pdm_submit('frmDTLRO','UPDATE');
    }
    }
    }
    else
    {
    AlertMsg = "";
    disableButtons();
    showAlertMsg("Não é permitido atualizar o status para a tarefa: $args.task.sym.");
    return;
    }
    }



  • 4.  Re: WF approval button

    Posted Sep 16, 2016 09:54 AM

    The other change I'm trying to do, is using this function, this one set the form to edit mode, but not change the status to Approved...

     

    <PDM_MACRO name=button Caption="Aprovar" Func="zApproval('APP')" hotkey_name="[A]" ID="bntapp">


    function zApproval() {
    var query_str = cfgCgi + "?SID=$prop.SID+FID=$prop.FID+OP=UPDATE" +
    "+FACTORY=cr_wf+PERSID=" + "$args.persistent_id" + "+KEEP.new_status="; // here might be ID instead of persistent_id due to chg factory specification.
    browseWithURL(query_str);
    }



  • 5.  Re: WF approval button

    Posted Sep 22, 2016 10:45 AM

    thiagojoseoliveira, this can be done in two ways:

    1- Creating a new OP and call it as the orderwf_aprove_console form (need a new spel)

    2- Creating a javascript to make the dirty work on the form.

     

    I made this change as follows (can be improved):

     

    Inside the head tag (I put in the end, before </head>) on the detail_cr_wf.htmpl

     

    function z_salvaStatusSolesp()
    {
       if("$args.KEEP.status_code" =="APR")
       {
          document.main_form.elements['SET.status'].value='APR';

          //if you want just click at the button to approve and save automatically, uncomment the line below and create a new line to put some default comment.
          //document.main_form.submit(); 
       }
       else if("$args.KEEP.status_code" =="REJ")
             document.main_form.elements['SET.status'].value='REJ';

             

             document.main_form.elements['SET.description'].focus();
    }

    //This define the status on the temporary form
    function z_defineStatus(status)
    {
          var frm = document.forms["zSolespForm"];
          frm.elements["KEEP.status_code"].value = status;
          document.zSolespForm.submit();
    }

     

    Below the line <PDM_INCLUDE FILE=std_body.htmpl [...], create a new form to host temporary values.

     

    <!-- Customizado -->

    <PDM_IF "$prop.form_name_3" != "edit">
    <FORM NAME="zSolespForm">
    <INPUT TYPE=HIDDEN NAME=OP VALUE=UPDATE>
    <INPUT TYPE=HIDDEN NAME=FACTORY VALUE=cr_wf>
    <INPUT TYPE=HIDDEN NAME=PERSID VALUE="$args.persistent_id">
    <INPUT TYPE=HIDDEN NAME=KEEP.aprovado VALUE="1">
    <input TYPE=HIDDEN NAME=DESCRIPTION>
    <input TYPE=HIDDEN NAME=KEEP.status_code> <!-- This is the most important value -->
    <INPUT TYPE=HIDDEN NAME=NEXT_PERSID VALUE="$args.persistent_id">
    <INPUT TYPE=HIDDEN NAME=SET.id VALUE="$args.id">
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
    docWriteln('<INPUT TYPE=HIDDEN NAME=SID VALUE='+cfgSID+'>');
    docWriteln('<INPUT TYPE=HIDDEN NAME=FID VALUE='+cfgFID+'>');
    //document.write("<INPUT TYPE=HIDDEN NAME=KEEP.aprovado VALUE=\"0\">");
    </SCRIPT>
    </FORM>
    </PDM_IF>

     

    Above the line <PDM_FORM NAME="frmDTLRO">, put:

     

    <script type="text/javascript">
    <PDM_MACRO name=btnStartRow>

    //Customizado - Cria botões 
    if (allow_wf_edit() && "$args.status.code" != "WAIT" && "$args.status.code" != "REOPWAIT" && cfgMOPreviewMode == 0)
    {
    var fieldset = "<td>";
    if ( _browser.isIe )
    fieldset += "<fieldset>";
    else
    fieldset += "<fieldset class=firefox_fieldset>";
    var legend = "Ações";
    docWriteln(fieldset + "<legend class=button_legend>" + legend + "</legend>");

     

    <PDM_MACRO name=btnStartRow>
    <PDM_MACRO name=button Caption="Aprovar" Func="z_defineStatus('APR');" hotkey_name="APR" ID="APRSOLESP" Tooltip="Aprovar SOLESP">
    <PDM_MACRO name=button Caption="Rejeitar" Func="z_defineStatus('REJ');" hotkey_name="REJ" ID="REJSOLESP" Tooltip="Rejeitar SOLESP">

     

    docWriteln("</fieldset></td></tr></table>");
    }
    </script>

     

    Now, change the body as below

     

    <!-- Customizado -->
    <PDM_IF "$args.KEEP.aprovado" == "1" && "$prop.form_name_3" == "edit">
    <body class="detailro" onload="z_salvaStatusSolesp()" onunload="unloadActions()">
    <PDM_ELSE>
    <body class="detailro" onunload="unloadActions()">
    </PDM_IF>

     

    The first function define a value to KEEP.status and KEEP.aprovado variables and submit the form, refreshing the form and calling the onload event on body tag which call the another function in which saves the value at the right form.

     

    Good luck!



  • 6.  Re: WF approval button

    Posted Sep 22, 2016 01:07 PM
      |   view attached

    Hi Daniel,

     

    I tried to follow your instructions, but I think I failed on some part.
    I've attached my detail_cr_wf.htmpl, can you help me to find what I did wrong? =/

    Attachment(s)

    zip
    detail_cr_wf.htmpl.zip   3 KB 1 version


  • 7.  Re: WF approval button

    Posted Sep 22, 2016 01:41 PM
      |   view attached

    They are in wrong places. Try my form attached and change it like you prefer.

    Attachment(s)

    zip
    detail_cr_wf.htmpl.zip   2 KB 1 version


  • 8.  Re: WF approval button

    Posted Sep 22, 2016 02:08 PM

    Hi Daniel,

     

    I need to the employee's role make this approvals, I've customized the allow_wf_edit, with this code below to enable the edit button to employee's role.
    Can I use this buttons with this customization?

     

    function allow_wf_edit() {
    if ("$args.status.allow_task_update" == "1") {
    return true;
    }
    if ("$args.status.task_complete" == "1" && reopen_id != 0) {
    var has_reopen = false;
    <PDM_LIST SOURCE=args.behavior_templates PREFIX=list WHERE=" " FACTORY=bhvtpl>
    if($list.context_attrval==reopen_id) { has_reopen=true; }
    </PDM_LIST>
    if (has_reopen) {
    return true;
    }
    }
    return false;
    }
    if (allow_wf_edit()) {
    <PDM_MACRO name=button Caption="Editar[d]" Func="pdm_submit('frmDTLRO','UPDATE')" hotkey_name="Edit[d]" ID=btn001 Width=120>
    }



  • 9.  Re: WF approval button

    Posted Sep 22, 2016 02:23 PM

    Acredito que pode usar sim...normal



  • 10.  Re: WF approval button

    Posted Sep 22, 2016 03:47 PM

    Então Daniel, eu estou tentando encaixar essa função que mandei acima, mas não to conseguindo, você consegue me ajudar a identificar o que pode estar ocorrendo?

     

    Eu tentei colocar o código da função antes do

    if (allow_wf_edit)...

     

    Mas não deu certo, sabe o que pode ser?



  • 11.  Re: WF approval button

    Posted Sep 22, 2016 03:48 PM

    Ficou conforme abaixo, mas não funciona.

     

    //Customizado - Cria botões
    function allow_wf_edit() {
    if ("$args.status.allow_task_update" == "1") {
    return true;
    }
    if ("$args.status.task_complete" == "1" && reopen_id != 0) {
    var has_reopen = false;
    <PDM_LIST SOURCE=args.behavior_templates PREFIX=list WHERE=" " FACTORY=bhvtpl>
    if($list.context_attrval==reopen_id) { has_reopen=true; }
    </PDM_LIST>
    if (has_reopen) {
    return true;
    }
    }
    return false;
    }
    if (allow_wf_edit() && "$args.status.code" != "WAIT" && "$args.status.code" != "REOPWAIT" && cfgMOPreviewMode == 0)
    {
    var fieldset = "<td>";
    if ( _browser.isIe )
    fieldset += "<fieldset>";
    else
    fieldset += "<fieldset class=firefox_fieldset>";
    var legend = "Ações";
    docWriteln(fieldset + "<legend class=button_legend>" + legend + "</legend>");

    <PDM_MACRO name=btnStartRow>
    <PDM_MACRO name=button Caption="Aprovar" Func="z_defineStatus('APP');" hotkey_name="APR" ID="APRSOLESP" Tooltip="Aprovar SOLESP">
    <PDM_MACRO name=button Caption="Rejeitar" Func="z_defineStatus('REJ');" hotkey_name="REJ" ID="REJSOLESP" Tooltip="Rejeitar SOLESP">

    docWriteln("</fieldset></td></tr></table>");
    }
    </script>



  • 12.  Re: WF approval button

    Posted Sep 23, 2016 09:49 AM

    Você deve ter posto a função dentro do BODY ao invés de colocar entre o HEAD. Procura pela tag </head> e coloca as funções acima dela. Os botões ficam onde estão, mova somente as functions.