Created
June 4, 2019 18:27
-
-
Save leo-bianchi/cb2e17cb14e88675bd115d3a828b7358 to your computer and use it in GitHub Desktop.
Catalog Client Script and Script Include
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
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); | |
} | |
} |
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
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