Histórico da Página
HTML |
---|
<div id="main-content" class="wiki-content group"> <p> Data update in Protheus is also performed via WebServices as seen in the validation using the <strong>afterProcessFinish</strong> process event that is run at the end of the request. </p> <p> </p> <blockquote> <p> function <strong>afterProcessFinish</strong>(processId){ </p> <p>var wsService = ServiceManager.getService("WSCLIENTE");</p> <p>var serviceHelper = wsService.getBean();</p> <p>var serviceLocator = serviceHelper.instantiate("localhost.WSCLIENTELocator");</p> <p>var service = serviceLocator.getWSCLIENTESOAP();</p> <p>var SA1 = new XML("<SA1/>");</p> <p> </p> <p>SA1.A1_COD = hAPI.getCardValue("A1_COD");</p> <p>SA1.A1_LOJA = hAPI.getCardValue("A1_LOJA");</p> <p>SA1.A1_TIPO = hAPI.getCardValue("A1_TIPO");</p> <p>SA1.A1_PESSOA = hAPI.getCardValue("A1_PESSOA");</p> <p>SA1.A1_NOME = hAPI.getCardValue("A1_NOME");</p> <p>SA1.A1_NREDUZ = hAPI.getCardValue("A1_NREDUZ");</p> <p>SA1.A1_END = hAPI.getCardValue("A1_END");</p> <p>SA1.A1_MUN = hAPI.getCardValue("A1_MUN");</p> <p>SA1.A1_EST = hAPI.getCardValue("A1_EST");</p> <p> </p> <p>try {</p> <p>    ret = service.<strong>INCLUIR</strong>(new java.lang.String(SA1.toXMLString()).getBytes()); </p> <p>}</p> <p>catch(erro){</p> <p>   throw erro.message</p> <p>}</p> <p>}</p> </blockquote> <h1 id="id-2.4AtualizaçãodoProtheus-MVC">MVC</h1> <p> The validation process of a MVC routine is also performed using the FWWSMODEL WebService (<a href="http://hostexemplo:8080/ws/fwwsmodel.apw?wsdl" class="external-link" rel="nofollow">http://hostexemplo:8080/ws/fwwsmodel.apw?wsdl</a>) with the invocation of the <strong>GETXMLDATADETAIL</strong> method that returns the XML of the model to populate the data and the <strong>PUTXMLDATA</strong> method to save the XML. </p> <p> </p> <blockquote> <p> function <strong>afterProcessFinish</strong>(processId){ </p> <p>var wsService = ServiceManager.getService("TOTVS_FWMVC");</p> <p>var serviceHelper = wsService.getBean();</p> <p>var serviceLocator = serviceHelper.instantiate("br.com.totvs.webservices.fwwsmodel_apw.FWWSMODELLocator");</p> <p>var service = serviceLocator.getFWWSMODELSOAP();</p> <p> var err = {message:"", <a href="http://emptytrue" class="external-link" rel="nofollow">empty:true</a>}; </p> <p>var ret, xml;</p> <p> </p> <p>try {</p> <p>    ret = service.<strong>GETXMLDATADETAIL</strong>([],"MATA030_MVC"); </p> <p>   xml = new XML(new String(new java.lang.String(ret)).replace(/<\?.*\?>/g,""));</p> <p>}</p> <p>catch(erro){</p> <p>   throw erro.message;</p> <p>   return;</p> <p>}</p> <p> </p> <p>updateXMLFields(xml,err);</p> <p> </p> <p>eval("xml.@Operation = 3");</p> <p>try{</p> <p>    service.<strong>PUTXMLDATA</strong>([],"MATA030_MVC",new java.lang.String(xml.toXMLString()).getBytes()); </p> <p>} catch(e){</p> <p>   throw e.message;</p> <p>}</p> <p>}</p> <p> </p> <p>function updateXMLFields(node,err){</p> <p>var list = node.children();</p> <p>var name,value;</p> <p> </p> <p>for (var i=0;i<list.length();i++){</p> <p>   switch (Trim(eval("list[i][email protected]()"))){</p> <p>      case "FIELDS":</p> <p>         updateXMLFields(list[i],err);</p> <p>         break;</p> <p>      default:</p> <p>         name = list[i].name().localName;</p> <p>         value = hAPI.getCardValue(name);</p> <p>         if (value != null)</p> <p>            list[i].value = convertValue(name,list[i],value,err);</p> <p>         break;</p> <p>   }</p> <p>   if (err.message.length > 0)</p> <p>      break;</p> <p>}</p> <p>}</p> <p> </p> <p>function convertValue(name,struct,value,err){</p> <p>var y,m,d,n,len,str,reg</p> <p>var setYear = new Date().getFullYear().toString().substring(0,2);</p> <p>var setDate = "dd/mm/yyyy";</p> <p>var yCount = setDate.match(/yyyy/) ? 4 : 2;</p> <p>var hasErr = false;</p> <p> </p> <p>value = value.trim();</p> <p> </p> <p>switch (eval("[email protected]()")){</p> <p>case "D":</p> <p>   if (value.replace("/","").trim() != ""){</p> <p>      len = value.length();</p> <p>      d = setDate.indexOf("d");</p> <p>      m = setDate.indexOf("m");</p> <p>      y = setDate.indexOf("y");</p> <p> </p> <p>      if (d + 2 > len || m + 2 > len || y + yCount > len){</p> <p>         hasErr = true;</p> <p>      }</p> <p>      else{</p> <p>         str = value.substr(m,2) + value.substr(d,2);</p> <p>         if (yCount == 4)</p> <p>            str = value.substr(y,4) + str;</p> <p>         else</p> <p>            str = setYear + value.substr(y,2) + str;</p> <p> </p> <p align="left">         if (str.match(/((((19|20)(([02468][048])|([13579][26]))0229))|((19|20)[0-9][0-9])((((0[1-9])|(1[0-2]))((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))31)|(((0[1,3-9])|(1[0-2]))(29|30)))))/g))</p> <p>            value = new java.lang.String(str);</p> <p>         else</p> <p>            hasErr = true;</p> <p>      }</p> <p> </p> <p>      if (hasErr)</p> <p>         err.message = "The field "+eval("struct.@info")+" ("+name+") has an invalid date";</p> <p>      else</p> <p>         err.empty = false;</p> <p>   }</p> <p>   break;</p> <p>case "N":</p> <p>   len = eval("[email protected]().split(',')");</p> <p>   if (len[1] == "0"){</p> <p>      reg = new RegExp("^[0-9]{1,"+len[0]+"}$");</p> <p>      str = value.replace(",","");</p> <p>      if(!reg.test(str)){</p> <p>         str = value.replace(".","");</p> <p>         if(!reg.test(str)){</p> <p>            err.message = "The field "+eval("struct.@info")+" ("+name+") has an invalid number (value or size)"</p> <p>            hasErr = true;</p> <p>            break;</p> <p>         }</p> <p>      }</p> <p> </p> <p>      if (!hasErr){</p> <p>         n = parseInt(str);</p> <p>         if (!isNaN(n)){</p> <p>            value = new java.lang.String(str);</p> <p>            if (n > 0)</p> <p>               err.empty = false;</p> <p>         }</p> <p>      }</p> <p>   }</p> <p>   else{</p> <p>      reg = new RegExp("^0$|^0\.[0-9]{1,"+len[1]+"}$|^[0-9]{0,"+len[0]+"}(\.[0-9]{1,"+len[1]+"})?$");</p> <p>      str = value.replace(".","").replace(",",".");</p> <p>      if(!reg.test(str)){</p> <p>         str = value.replace(",","");</p> <p>         if(!reg.test(str)){</p> <p>            err.message = "The field "+eval("struct.@info")+" ("+name+") has an invalid number (value or size)"</p> <p>            hasErr = true;</p> <p>            break;</p> <p>         }</p> <p>      }</p> <p>            </p> <p>      if (!hasErr){</p> <p>         n = parseFloat(str);</p> <p>         if (!isNaN(n)){</p> <p>            value = new java.lang.String(str);</p> <p>            if (n > 0)</p> <p>               err.empty = false;</p> <p>         }</p> <p>      }</p> <p>   }</p> <p>   break;</p> <p>default:</p> <p>   if (value != "")</p> <p>      err.empty = false;</p> <p>   break;</p> <p>}</p> <p>return value;</p> <p>}</p> <p>function Trim(str){return str.replace(/^\s+|\s+$/g,"");}</p> </blockquote> <p> </p> <h1 id="id-2.4AtualizaçãodoProtheus-RotinaAutomática(Modelo1)">Automatic Routine (Model 1)</h1> <p> Since automatic routines perform the update after validation, instead of using the <strong>afterProcessFinish event, use the beforeTaskSave event when the process is in the end activity. In addition to the MVC WebService, also use </strong>the <strong>FWWSMODEL</strong> (<a href="http://hostexemplo:8080/ws/fwwsecm.apw?wsdl" class="external-link" rel="nofollow">http://hostexemplo:8080/ws/fwwsecm.apw?wsdl</a>) by calling the <strong>PUTDATA</strong> method. </p> <p> </p> <blockquote> <p>#include "totvs.ch"</p> <p>User Function WSMVC()</p> <p>Local cName := "TOTVS_FWWSECM"</p> <p> Local cURL := "<a href="http://hostname:8080/ws/fwwsecm.apw?wsdl" class="external-link" rel="nofollow">http://hostname:8080/ws/fwwsecm.apw?wsdl</a>" </p> <p align="left">Local cDescription := "TOTVS Microsiga Protheus service for integrating automatic routines with ECM"</p> <p>Local aService := FWWFGetService(cName)</p> <p> </p> <p> If Empty(aService) .and. <strong>FWWFPutService(cName,cUrl,cDescription)</strong> </p> <p>   MsgInfo("Service successfully registered")</p> <p>EndIf</p> <p>Return</p> <p> </p> <p> <strong>beforeTaskSave</strong> event: </p> <p> </p> <p> function <strong>beforeTaskSave</strong>(colleagueId,nextSequenceId,userList){ </p> <p>var wsService = ServiceManager.getService("TOTVS_FWMVC");</p> <p>var serviceHelper = wsService.getBean();</p> <p align="left">var serviceLocator = serviceHelper.instantiate("br.com.totvs.webservices.fwwsmodel_apw.FWWSMODELLocator");</p> <p>var service = serviceLocator.getFWWSMODELSOAP();</p> <p> var err = {message:"", <a href="http://emptytrue" class="external-link" rel="nofollow">empty:true</a>}; </p> <p>var ret, xml;</p> <p> </p> <p>try {</p> <p>    ret = service.<strong>GETXMLDATADETAIL</strong>([],"MATA030_MVC"); </p> <p>   xml = new XML(new String(new java.lang.String(ret)).replace(/<\?.*\?>/g,""));</p> <p>}</p> <p>catch(erro){</p> <p>   throw erro.message;</p> <p>   return;</p> <p>}</p> <p> </p> <p>updateXMLFields(xml,err);</p> <p> </p> <p>if (err.message.length > 0){</p> <p>   throw err.message;</p> <p>}</p> <p>else if (err.empty){</p> <p>   throw "Fill out form";</p> <p>}</p> <p>else{</p> <p>   wsService = ServiceManager.getService("TOTVS_FWWSECM");</p> <p>   serviceHelper = wsService.getBean();</p> <p align="left">   serviceLocator = serviceHelper.instantiate("br.com.totvs.webservices.fwwsecm_apw.FWWSECMLocator");</p> <p>   service = serviceLocator.getFWWSMODELSOAP();</p> <p> </p> <p>   eval("xml.@Operation = 3");</p> <p>   try{</p> <p>       service.<strong>PUTDATA</strong>([],"SA1","MATA030",new java.lang.String(xml.toXMLString()).getBytes());; </p> <p>   } catch(e){</p> <p>      throw e.message;</p> <p>   }</p> <p>}</p> <p>}</p> <p> </p> <p>function updateXMLFields(node,err){</p> <p>var list = node.children();</p> <p>var name,value;</p> <p> </p> <p>for (var i=0;i<list.length();i++){</p> <p>   switch (Trim(eval("list[i][email protected]()"))){</p> <p>      case "FIELDS":</p> <p>         updateXMLFields(list[i],err);</p> <p>         break;</p> <p>      default:</p> <p>         name = list[i].name().localName;</p> <p>         value = hAPI.getCardValue(name);</p> <p>         if (value != null)</p> <p>            list[i].value = convertValue(name,list[i],value,err);</p> <p>         break;</p> <p>   }</p> <p>   if (err.message.length > 0)</p> <p>      break;</p> <p>}</p> <p>}</p> <p> </p> <p>function convertValue(name,struct,value,err){</p> <p>var y,m,d,n,len,str,reg</p> <p>var setYear = new Date().getFullYear().toString().substring(0,2);</p> <p>var setDate = "dd/mm/yyyy";</p> <p>var yCount = setDate.match(/yyyy/) ? 4 : 2;</p> <p>var hasErr = false;</p> <p> </p> <p>value = value.trim();</p> <p> </p> <p>switch (eval("[email protected]()")){</p> <p>case "D":</p> <p>   if (value.replace("/","").trim() != ""){</p> <p>      len = value.length();</p> <p>      d = setDate.indexOf("d");</p> <p>      m = setDate.indexOf("m");</p> <p>      y = setDate.indexOf("y");</p> <p> </p> <p>      if (d + 2 > len || m + 2 > len || y + yCount > len){</p> <p>         hasErr = true;</p> <p>      }</p> <p>      else{</p> <p>         str = value.substr(m,2) + value.substr(d,2);</p> <p>         if (yCount == 4)</p> <p>            str = value.substr(y,4) + str;</p> <p>         else</p> <p>            str = setYear + value.substr(y,2) + str;</p> <p> </p> <p align="left">         if (str.match(/((((19|20)(([02468][048])|([13579][26]))0229))|((19|20)[0-9][0-9])((((0[1-9])|(1[0-2]))((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))31)|(((0[1,3-9])|(1[0-2]))(29|30)))))/g))</p> <p>            value = new java.lang.String(str);</p> <p>         else</p> <p>            hasErr = true;</p> <p>      }</p> <p> </p> <p>      if (hasErr)</p> <p>         err.message = "The field "+eval("struct.@info")+" ("+name+") has an invalid date";</p> <p>      else</p> <p>         err.empty = false;</p> <p>   }</p> <p>   break;</p> <p>case "N":</p> <p>   len = eval("[email protected]().split(',')");</p> <p>   if (len[1] == "0"){</p> <p>      reg = new RegExp("^[0-9]{1,"+len[0]+"}$");</p> <p>      str = value.replace(",","");</p> <p>      if(!reg.test(str)){</p> <p>         str = value.replace(".","");</p> <p>         if(!reg.test(str)){</p> <p>            err.message = "The field "+eval("struct.@info")+" ("+name+") has an invalid number (value or size)"</p> <p>            hasErr = true;</p> <p>            break;</p> <p>         }</p> <p>      }</p> <p> </p> <p>      if (!hasErr){</p> <p>         n = parseInt(str);</p> <p>         if (!isNaN(n)){</p> <p>            value = new java.lang.String(str);</p> <p>            if (n > 0)</p> <p>               err.empty = false;</p> <p>         }</p> <p>      }</p> <p>   }</p> <p>   else{</p> <p>      reg = new RegExp("^0$|^0\.[0-9]{1,"+len[1]+"}$|^[0-9]{0,"+len[0]+"}(\.[0-9]{1,"+len[1]+"})?$");</p> <p>      str = value.replace(".","").replace(",",".");</p> <p>      if(!reg.test(str)){</p> <p>         str = value.replace(",","");</p> <p>         if(!reg.test(str)){</p> <p>            err.message = "The field "+eval("struct.@info")+" ("+name+") has an invalid number (value or size)"</p> <p>            hasErr = true;</p> <p>            break;</p> <p>         }</p> <p>      }</p> <p>            </p> <p>      if (!hasErr){</p> <p>         n = parseFloat(str);</p> <p>         if (!isNaN(n)){</p> <p>            value = new java.lang.String(str);</p> <p>            if (n > 0)</p> <p>               err.empty = false;</p> <p>         }</p> <p>      }</p> <p>   }</p> <p>   break;</p> <p>default:</p> <p>   if (value != "")</p> <p>      err.empty = false;</p> <p>   break;</p> <p>}</p> <p>return value;</p> <p>}</p> <p>function Trim(str){return str.replace(/^\s+|\s+$/g,"");}</p> </blockquote> <p> </p> <p> </p> <p> </p> </div> |
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas