Adicionar valores em campos pelo com HTM5 e botão de ação

Bom dia!

Estou tentando criar um dashboard com HTML5, para adicionar valores em uma tabela no banco que eu criei. A ideia é ter um dash principal com a consulta sql e outra que é a detalhe feita em HTML5, no entanto, não estou conseguindo inserir dados na tabela por conta de um problema de PK. segue imagem para detalhe.

Isso acontece sempre que utilizo o botão de ‘Salvar’ que criei em HTML5. Eu faço uma requisição para chamar meu botão de ação e preencho os paramêtros para dar um insert no banco de dados.

código JS: > function SalvarDadosRepresentante(session) {

        if(validarCamposObrigatorios()) {
            var request = new XMLHttpRequest();
            var stringXML = '<serviceRequest serviceName="ActionButtonsSP.executeJava">' +
                                    '<requestBody>' +
                                        '<javaCall actionID="130">' +
                                            '<params>' +                                           
                                                '<param type="I" paramName="ESTATUAL">' +
                                                    '<![CDATA[' + document.getElementById("estoqueAtual").value + ']]>' + 
                                                '</param>' +
                                            '</params>' +
                                            '<params>' +                                           
                                                '<param type="S" paramName="OBSERVACAO">' +
                                                    '<![CDATA[' + document.getElementById("observacao").value + ']]>' + 
                                                '</param>' +
                                            '</params>' +
                                            '<params>' +                                           
                                                '<param type="S" paramName="DTREF">' +
                                                    '<![CDATA[' + document.getElementById("dataReferencia").value + ']]>' + 
                                                '</param>' +
                                            '</params>' +
                                            '<params>' +                                           
                                                '<param type="I" paramName="QTDPREVISTA">' +
                                                    '<![CDATA[' + document.getElementById("previsao").value + ']]>' + 
                                                '</param>' +
                                            '</params>' +
                                            '<params>' +                                           
                                                '<param type="I" paramName="PACATEND">' +
                                                    '<![CDATA[' + document.getElementById("pacientes").value + ']]>' + 
                                                '</param>' +
                                            '</params>' +
                                            '<params>' +                                           
                                                '<param type="I" paramName="NUEDITAL">' +
                                                    '<![CDATA[' + '${NUEDITAL}' + ']]>' + 
                                                '</param>' +
                                            '</params>' +
                                            '<params>' +                                           
                                                '<param type="I" paramName="SEQUENCIA">' +
                                                    '<![CDATA[' + '${SEQUENCIA}' + ']]>' + 
                                                '</param>' +
                                            '</params>' +      
                                            '<params>' +                                           
                                                '<param type="I" paramName="NUOBS">' +
                                                    '<![CDATA[' + '${NUOBS}' + ']]>' + 
                                                '</param>' +
                                            '</params>' +                                        
                                            '<rows>' +
                                                '<row>' +
                                                    '<field fieldName="NUEDITAL">' + '${NUEDITAL}' + '</field>' +
                                                '</row>' +
                                                '<row>' +
                                                    '<field fieldName="SEQUENCIA">' + '${SEQUENCIA}' + '</field>' +
                                                '</row>' +
                                                '<row>' +
                                                    '<field fieldName="NUOBS">' + '${NUOBS}' + '</field>' +
                                                '</row>' +
                                            '</rows>' +
                                        '</javaCall>' +
                                    '</requestBody>' +
                                '</serviceRequest>';   
                                console.log(stringXML)                                
            var parser = new DOMParser();
            body = parser.parseFromString(stringXML, "text/xml");
            request.open("POST", urlSankhya + "/mge/service.sbr?serviceName=ActionButtonsSP.executeJava&mgeSession=" + session);
            request.setRequestHeader("Content-Type", "application/xml");
            return request;
        }
    }

Quando eu olho na ferramenta de desenvolver os paramêtros estão sendo preenchidos mas esse erro persiste. Segue o código do botão.

public class BtnSalvarDadosRepresentates implements AcaoRotinaJava{

@Override
public void doAction(ContextoAcao contexto) throws Exception {

  JapeSession.SessionHandle hnd = null;
  JdbcWrapper jdbc = null;

  /*BigDecimal nueditalPA = new BigDecimal((Integer) contexto.getParam("NUEDITAL"));
  BigDecimal sequenciaPA = new BigDecimal((Integer) contexto.getParam("SEQUENCIA"));*/
  BigDecimal estoqueAtual = new BigDecimal((Integer) (contexto.getParam("ESTATUAL") != null ? (int) contexto.getParam("ESTATUAL") : 0));
  String observacao = (String) contexto.getParam("OBSERVACAO");
  Timestamp dataReferencia = (Timestamp) contexto.getParam("DTREF");
  BigDecimal previsao = new BigDecimal((Integer) (contexto.getParam("QTDPREVISTA") != null ? (int) contexto.getParam("QTDPREVISTA") : 0));
  BigDecimal pacientes = new BigDecimal((Integer) (contexto.getParam("PACATEND") != null ? (int) contexto.getParam("PACATEND") : 0));
  //BigDecimal nuobs = new BigDecimal((Integer) (contexto.getParam("NUOBS") != null ? (int) contexto.getParam("NUOBS") : 0));

  try {			
  	hnd = JapeSession.open();
  	jdbc = EntityFacadeFactory.getDWFFacade().getJdbcWrapper();
  	jdbc.openSession();

  	JapeWrapper AD_TGLREP = JapeFactory.dao("AD_TGLREP");				
  	
  	BigDecimal nuedital = BigDecimal.ZERO;
  	BigDecimal sequencia = BigDecimal.ZERO;
  	BigDecimal nuobs = BigDecimal.ZERO;
  	
  	Registro[] linhas = contexto.getLinhas();			
  	for(Registro linha : linhas) {
  		nuedital = new BigDecimal((Integer) linha.getCampo("NUEDITAL"));
  		sequencia = new BigDecimal((Integer) linha.getCampo("SEQUENCIA"));
  		nuobs = new BigDecimal((Integer) linha.getCampo("NUOBS"));
  	
  	//DynamicVO licitRep = AD_TGLREP.findOne("SEQUENCIA = " + sequencia + " AND NUEDITAL = " + nuedital);
  		
  		/*if(licitRep != null) {
  			
  			AD_TGLREP.prepareToUpdate(licitRep)
  				.set("ESTATUAL", estoqueAtual)
  				.set("OBSERVACAO", (observacao != null ? observacao : ""))
  				.set("DTREF", dataReferencia)
  				.set("QTDPREVISTA", previsao)
  				.set("PACATEND", pacientes)
  			.update();
  		
  			contexto.setMensagemRetorno("As informações sobre esse item foram atualizadas!");
  		
  		} else {*/
  		
  			AD_TGLREP.create()
  				.set("NUOBS", nuobs)
  				.set("SEQUENCIA", sequencia)
  				.set("NUEDITAL", nuedital)
  				.set("ESTATUAL", estoqueAtual)
  				.set("OBSERVACAO", (observacao != null ? observacao : ""))
  				.set("DTREF", dataReferencia)
  				.set("QTDPREVISTA", previsao)
  				.set("PACATEND", pacientes)
  			.save();

  			contexto.setMensagemRetorno("Foi inserido novos dados para esse item!");
  		//}
  	}
  } catch (Exception e) {
  	e.printStackTrace();
  	throw new Exception(e.getMessage());
  } finally {
  	JapeSession.close(hnd);
  	JdbcWrapper.closeSession(jdbc);
  }

}

}

2 respostas