Skip to content

Instantly share code, notes, and snippets.

@brunogasparetto
Last active October 22, 2021 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunogasparetto/f73ea69a21eeee0315604a456b28a0a6 to your computer and use it in GitHub Desktop.
Save brunogasparetto/f73ea69a21eeee0315604a456b28a0a6 to your computer and use it in GitHub Desktop.
Fluig: Exemplo de Inserção de Pai Filho por Web Service em Widget
const response = await fetch(
`${WCMAPI.serverURL}/webdesk/ECMCardService?wsdl`,
{
method: "POST",
redirect: "follow",
credentials: "omit",
headers: {
"Content-Type": "text/xml;charset=utf-8"
},
body: createItemXml(documentId, novoIndice, conteudoDoItem)
}
)
.then(response => response.text())
.then(xmlText => (new DOMParser()).parseFromString(xmlText, "text/xml"));
const message = response.getElementsByTagName("webServiceMessage")[0].textContent;
if (message == "ok") {
FLUIGC.toast({
message: "Registro Salvo"
});
} else {
FLUIGC.toast({
message: "Problema ao Salvar o Registro.",
type: "danger"
});
}
/**
* Cria o XML de inserção de Item
*
* @param {number} documentId
* @param {number} index
* @param {object} conteudo
* @returns {string}
*/
function createItemXml(documentId, index, conteudo) {
return `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.dm.ecm.technology.totvs.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:updateCardData>
<username>${fluigUser.username}</username>
<password>${fluigUser.password}</password>
<companyId>${WCMAPI.organizationId}</companyId>
<cardId>${documentId}</cardId>
<cardData>
<item>
<field>tableid___${index}</field>
<value>tableItems</value>
</item>
<item>
<field>Autor___${index}</field>
<value>${loggedUser.name}</value>
</item>
<item>
<field>Registro___${index}</field>
<value>${conteudo.registro}</value>
</item>
<item>
<field>Valor___${index}</field>
<value>${conteudo.valor}</value>
</item>
</cardData>
</ws:updateCardData>
</soapenv:Body>
</soapenv:Envelope>`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment