Skip to content

Instantly share code, notes, and snippets.

@leo-bianchi
Created June 4, 2019 18:27
Show Gist options
  • Save leo-bianchi/cb2e17cb14e88675bd115d3a828b7358 to your computer and use it in GitHub Desktop.
Save leo-bianchi/cb2e17cb14e88675bd115d3a828b7358 to your computer and use it in GitHub Desktop.
Catalog Client Script and Script Include
function onLoad() {
var ga = new GlideAjax('GetUserData');
ga.addParam('sysparm_name', 'getData');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var obj = JSON.parse(answer);
g_form.setValue("cnh", obj.cnh);
g_form.setValue("cpf", obj.cpf);
g_form.setValue("data_de_nascimento", obj.dataNascimento);
}
}
var GetUserData = Class.create();
GetUserData.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getData : function() {
// Instancia objeto vazio
var obj = {};
// Consulta a tabela sys_user
var gr = new GlideRecord("sys_user");
// Pega o ID do usuário atual
gr.addEncodedQuery("sys_id="+gs.getUserID());
// Executa a Query
gr.query();
// Verifica se encontrou algum dado
if(gr.next()) {
// Coloca os dados dentro do objeto
obj.cpf = gr.u_cpf_user.toString();
obj.cnh = gr.u_cnh_user.toString();
obj.dataNascimento = gr.u_data_nascimento.toString();
// Stringify
return JSON.stringify(obj);
} else {
// Se não encontrar o registro
return gs.info("Not find");
}
},
type: 'GetUserData'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment