function displayFields(form, customHTML) { var activity = getValue('WKNumState'); var userId = getValue('WKUser'); form.setShowDisabledFields(true); form.setHidePrintLink(true); form.setValue("WKNumProces", getValue('WKNumProces')); form.setValue("activity", activity); form.setValue("formMode", form.getFormMode()); form.setValue("empresa", getValue("WKCompany")); var c1 = DatasetFactory.createConstraint("colleagueId", userId, userId, ConstraintType.MUST); var filter = new Array(c1); var fields = new Array("colleagueName"); var retorno = DatasetFactory.getDataset("colleague", fields, filter, null); //requester if (activity == 0) { form.setValue("usuario_abertura", retorno.getValue(0, "colleagueName")); form.setValue("requesterMail", retorno.getValue(0, "mail")); form.setValue("requesterId", userId); } else { form.setValue("currentUserName", retorno.getValue(0, "colleagueName")); form.setValue("currentUsermail", retorno.getValue(0, "mail")); form.setValue("currentUserId", userId); } // ✅ Quando for atividade de aprovação do gestor if (activity == 121) { var hoje = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date()); form.setValue("user_validacao_gestor", retorno.getValue(0, "colleagueName")); form.setValue("data_validacao_gestor", hoje); } if (activity == 133) { var hoje = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date()); form.setValue("gestor_validacao_aprova", retorno.getValue(0, "colleagueName")); form.setValue("data_validacao_aprova_gestor", hoje); } if (activity == 137) { var hoje = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date()); form.setValue("user_validacao_aprova", retorno.getValue(0, "colleagueName")); form.setValue("data_validacao_aprova", hoje); } if (activity == 147) { var hoje = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date()); form.setValue("gerf_validacao_aprova", retorno.getValue(0, "colleagueName")); form.setValue("data_validacao_aprova_gerf", hoje); } if (activity == 18) { var hoje = new java.text.SimpleDateFormat("dd/MM/yyyy").format(new java.util.Date()); form.setValue("userValidacaoItens", retorno.getValue(0, "colleagueName")); form.setValue("dataValidacaoItens", hoje); } // ✅ Injetar dados da SC do Protheus (se já tiverem sido preenchidos no servicetask) var camposSC = [ "numeroSCProtheus", "statusSCProtheus", "solicitanteSCProtheus", "emissaoSCProtheus", "qtdItensSCProtheus", "dataCadastroSCProtheus", "horaCadastroSCProtheus" ]; camposSC.forEach(function(campo) { var valor = form.getValue(campo); if (valor) { customHTML.append(""); } }); // cor no status var status = form.getValue("statusSCProtheus"); if (status) { var badgeClass = "badge bg-secondary"; if (status.toLowerCase().indexOf("sucesso") >= 0) badgeClass = "badge bg-success"; if (status.toLowerCase().indexOf("erro") >= 0) badgeClass = "badge bg-danger"; customHTML.append(""); } // Consultar informações adicionais da SC no Protheus var numSC = form.getValue("numeroSCProtheus"); if (numSC) { try { var c1 = DatasetFactory.createConstraint("numeroSCProtheus", numSC, numSC, ConstraintType.MUST); var ds = DatasetFactory.getDataset("ds_consultaSC", null, [c1], null); if (ds && ds.rowsCount > 0) { var status = ds.getValue(0, "STATUS") || ""; var cotacao = ds.getValue(0, "C1_COTACAO") || ""; var pedido = ds.getValue(0, "C1_PEDIDO") || ""; // grava nos hidden inputs form.setValue("statusAtendimento", status); form.setValue("cotacaoSCProtheus", cotacao); form.setValue("pedidoSCProtheus", pedido); // mostra nos cards (HTML) customHTML.append(""); customHTML.append(""); customHTML.append(""); } } catch (e) { log.error("❌ Erro ao consultar dataset ds_consultaSC: " + e); } } try { var msgs = []; var numeroSC = form.getValue("numeroSCProtheus"); var cotacaoSC = form.getValue("cotacaoSCProtheus"); var pedidoSC = form.getValue("pedidoSCProtheus"); if (numeroSC) msgs.push("📌 Gerou SC Protheus nº " + numeroSC); if (cotacaoSC) msgs.push("📌 SC originou Cotação nº " + cotacaoSC); if (pedidoSC) msgs.push("📌 Cotação finalizou → Pedido nº " + pedidoSC); if (msgs.length === 0) { msgs.push("ℹ️ Nenhum dado de integração Protheus encontrado no formulário"); } // Monta conteúdo HTML do histórico var htmlHistorico = "