In the function below I need Volt to wait for the API response to continue processing, but I'm not getting it. Does anyone have any suggestions?
Get_User_Profile_AD: function(GrupoAD){
function INVOKE_SERVICE_getProfile_Callback(Results) {
voltmx.application.dismissLoadingScreen();
perfil = Results.records[0]["Perfil"];
alert("Seu perfil: " + perfil);
var ntf = new voltmx.mvc.Navigation("AppGroup/Menu");
ntf.navigate();
}
if (getPerfil_inputparam == undefined) {
var getPerfil_inputparam = {};
}
getPerfil_inputparam["serviceID"] = "SACTiberio$View_Busca_Perfil$get";
getPerfil_inputparam["options"] = {
"access": "online",
"CRUD_TYPE": "get"
};
//odataParams é onde enviamos o select em formato odata.
var odataParams = [];
odataParams.push("$filter=" + "GrupoAD eq '" + GrupoAD + "'");
getPerfil_inputparam["options"]["odataurl"] = odataParams.join("&");
var getPerfil_httpheaders = {};
getPerfil_inputparam["httpheaders"] = getPerfil_httpheaders;
var getPerfil_httpconfigs = {};
getPerfil_inputparam["httpconfig"] = getPerfil_httpconfigs;
SACTiberio$View_Busca_Perfil$get = mfobjectsecureinvokerasync(getPerfil_inputparam, "SACTiberio", "View_Busca_Perfil", INVOKE_SERVICE_getProfile_Callback);
}
Hi Rubens,
Have you check the same operation in Foundry? Were you able to get result for the input param into the odata filter?
Is your Foundry app published and linked with this Iris project?
The code appears to be correct; I would try to debug and check for output in the console logs.
Dai
Olá! Eu consegui alterando a lógica do código e usando Promises:
Get_User_Profile_AD: async function (GrupoAD) {
function invokeServiceGetProfile() {
return new Promise((resolve, reject) => {
function INVOKE_SERVICE_getProfile_Callback(Results) {
voltmx.application.dismissLoadingScreen();
if (Results && Results.records && Results.records.length > 0) {
resolve(Results.records[0]["Perfil"]);
} else {
reject("Nenhum perfil encontrado.");
}
}
let getPerfil_inputparam = {
serviceID: "SACTiberio$View_Busca_Perfil$get",
options: {
access: "online",
CRUD_TYPE: "get",
odataurl: `$filter=GrupoAD eq '${GrupoAD}'`
},
httpheaders: {},
httpconfig: {}
};
try {
mfobjectsecureinvokerasync(
getPerfil_inputparam,
"SACTiberio",
"View_Busca_Perfil",
INVOKE_SERVICE_getProfile_Callback
);
} catch (error) {
reject(error);
}
});
}
try {
voltmx.application.showLoadingScreen("loading", "Carregando perfil...", constants.LOADING_SCREEN_POSITION_FULL_SCREEN, true, true, {});
let perfil = await invokeServiceGetProfile(GrupoAD);
var ntf = new voltmx.mvc.Navigation("AppGroup/Menu");
ntf.navigate();
} catch (error) {
alert("Erro ao buscar perfil: " + error);
} finally {
voltmx.application.dismissLoadingScreen();
}
}