Last active
October 12, 2022 14:15
-
-
Save brunogasparetto/278d1ad433c392e4a0eafe512017c858 to your computer and use it in GitHub Desktop.
Funções auxiliares para requisições no TOTVS Fluig Platform. Recomendo criar uma Widget somente para ter os arquivos disponibilizados no próprio Fluig e então adicionar nos formulários e demais widgets quando necessário.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pega um dataset | |
* | |
* Wrapper para tornar a DatasetFactory.getDataset (da lib vcXMLRPC.js) em Promise. | |
* | |
* @param {string} dataset Nome do Dataset | |
* @param {string[]} fields Campos para retornar (pode ser null pra retornar todos) | |
* @param {Constraint[]} constraints Os filtros a aplicar ou null se não filtrar nada | |
* @param {string[]} sorters Campos para ordenar ou null para não ordenar. Pode colocar ;desc no campo para ordenar decrescente | |
* @returns {Promise<{columns: string[], values: object[]}>} | |
*/ | |
function getDataset(dataset, fields, constraints, sorters) { | |
return new Promise(function (resolve, reject) { | |
DatasetFactory.getDataset( | |
dataset, | |
fields, | |
constraints, | |
sorters, { | |
success: data => resolve(data), | |
error: () => reject(arguments) | |
} | |
); | |
}); | |
} | |
/** | |
* Executa uma chamada SOAP por POST para serviços do Fluig | |
* | |
* @param {string} url | |
* @param {string} xml | |
* @returns {Promise<XMLDocument>} | |
*/ | |
function makeSoapRequest(url, xml) { | |
return fetch(url, { | |
method: "POST", | |
redirect: "follow", | |
credentials: "omit", | |
headers: { | |
"Content-Type": "text/xml;charset=utf-8" | |
}, | |
body: xml | |
}) | |
.then(response => response.text()) | |
.then(xmlText => (new DOMParser()) | |
.parseFromString(xmlText, "text/xml")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment