ERROR

208 views
Skip to first unread message

con...@ecotronicbr.com

unread,
Oct 16, 2014, 7:42:39 PM10/16/14
to suppor...@runmyprocess.com
Hello,

I'm so hard trying to make a autocomplete widget with an API.

I tested connectors, CAPI and them are ok!

So now I'm trying to make the code for the WI in JS. I'm based in [Tech'Tuesday] Configuration of multi-selection & autocomplete widget video.

My CAPI returns like this example in a test:

{"nome_gera":"cia","gera_result":{"created":1413502503662,"value":[{"RG":null,"Cliente":true,"Bloqueado":false,"Pais":"Brasil","Tecnico":false,"Vendedor":false,"Salt":null,"CodigoUF":"33","LogradouroNumero":null,"Celular":null,"DataNascimento":"0001-01-01T00:00:00-02:00","Complemento":null,"Logradouro":"","NomeMae":null,"NomePai":null,"Naturalidade":null,"ID":"53908a6d7fc272077403c29e","Telefone":"(24) 3353-7300","Fonecedor":true,"VendedorPadrao":null,"IE":null,"Site":"www.cocacolabrasil.com.br","NomeFantasia":"CIA FLU - COCA COLA","Representada":false,"ValorMinimoCompra":0.0,"UF":"RJ","RazaoSocial":"COMPANHIA FLUMINENSE DE REFRIGERANTES LTDA","CNPJ_CPF":"31.456.338/0001-86","Senha":null,"Transportadora":false,"Cidade":"Porto Real","Email":null,"EmailLoginEcommerce":null,"CodigoMunicipio":"3304110","CEP":"27570000","PessoaFisica":false,"CodigoPais":"1058","Bairro":"","Ramo":"Industria"}],"size":1}}

So, I tryied to take for my case the code in that Tech Tuesday. The code is:

var report_to_timer;
$(#"id_gerador").select2({
placeholder : "Entre com o nome do gerador",
allowClear : true,
minimumInputLenght : 1,
query : function (query) {
var data = {
results : []
};
clearTimeout(report_to_timer)
report_to_timer = setTimeout(function () {
id_consulta_geradores_reee.trigger ({
"gera_result" : gera_result.values
}, {},
function(result) {
for (i = 0; i < Math.min(10, result.gera_result.lenght); i++) {
data.results.push({
nome : result.gera_result[i].NomeFantasia,
razao_social : result.gera_result[i].RazaoSocial
id : result.gera_result[i].ID,
cnpj_cpf : result.gera_result[i].CNPJ_CPF,
logradouro : result.gera_result[i].Logradouro,
num : result.gera_result[i].LogradouroNumero,
cidade : result.gera_result[i].Cidade,
uf : result.gera_result[i].CodigoUF,
complemento : result.gera_result[i].Complemento,
telefone : result.gera_result[i].Telefone,
IE : result.gera_result[i].IE
});
}
gera_result.callback(data);
},
function () {
alert("Erro buscando geradores de REEE");
}}
}, 200};
},
formatSelection : formatSelection,
initSelection : function (element, callback) {
var data = {};
if ("${id?default("")}" =!"") {
data = {
text : "",
razao_social : "${RazaoSocial?default("")}",
id : "${id?default("")}",
cnpj_cpf : "${cnpj_cpf?default("")}",
logradouro : "${logradouro?default("")}",
num : "${numero?default("")}",
cidade : "${cidade?default("")}",
uf : "${uf?default("")}",
complemento : "${complemento?default("")}",
telefone : "${telefone_principal?default("")}",
IE : "${ie?default("")}"
};
callback(data);
}
}
});

${"id_gerador"}.on("change", function (e) {

if (e.added != undefined) {
RMPApplication.set("selected_gerador_reee_id", e.added.id);
RMPApplication.setVariable("RazaoSocial", e.added.NomeFantasia);
RMPApplication.setVariable("cnpj_cpf", e.added.cnpj_cpf);
RMPApplication.setVariable("logradouro", e.added.logradouro);
RMPApplication.setVariable("numero", e.added.num);
RMPApplication.setVariable("cidade", e.added.cidade);
RMPApplication.setVariable("uf", e.added.uf);
RMPApplication.setVariable("complemento", e.added.complemento);
RMPApplication.setVariable("telefone_principal", e.added.telefone);
RMPApplication.setVariable("ie", e.added.ie);
} else {
RMPApplication.set("id", "");
RMPApplication.setVariable("RazaoSocial", "");
RMPApplication.setVariable("cnpj_cpf", "");
RMPApplication.setVariable("logradouro", "");
RMPApplication.setVariable("numero", "");
RMPApplication.setVariable("cidade", "");
RMPApplication.setVariable("uf", "");
RMPApplication.setVariable("complemento", "");
RMPApplication.setVariable("telefone_principal", "");
RMPApplication.setVariable("ie", "");
}

});

function formatSelection(result)
{
return result.name;
}

When I launch in test mode the WI, The box for search have the value X and when I click te JS Widget cams this message:

com.google.gwt.core.client.JavaScriptException: (SyntaxError) : Unexpected token ILLEGAL

The authentication method of my webservice is by a fixed token, that is informed in the Heather of my connector.

Can you help me?


Best regards

Bidisha Das

unread,
Oct 17, 2014, 12:32:30 AM10/17/14
to suppor...@runmyprocess.com, con...@ecotronicbr.com
Hi,
Did you plugin the following JS libraries in the footer of your Web Interface:  jQuery1.9.1, jQuery UI 1.10.1 and Select2 (jQuery plugin) 3.4.8 ?

Can you send me the code you are using in CAPI to get the respective output.

Also you can try with the js code am sending you in your WI.Just replace the variable names with your own value variables.& property names of your report. Please let me know if you face any issue or you can also send the code after you reform it.I can make the corrections in case not working.


Thanks & Regards
Bidisha
autocomplete_js.txt

ADMINISTRADOR ECOTRONIC

unread,
Oct 22, 2014, 9:42:07 PM10/22/14
to Bidisha Das, suppor...@runmyprocess.com
Hello, 

I'm trying to connect another cloud system to take the values from to put in my WI. 

I didn't undertood why I'm using a code in input of my CAPI if the other system needs the a input value to match the result.

In this code, if I understood, you are trying to take the values from a collection, but I have no data in collection. The data is from the sigecloud (www.sigecloud.com.br), a third party system, that have an API with http verbs post and get.

I'm attached the API documentation in portuguese. 


Please help me!


Best regards

2014-10-18 17:25 GMT-03:00 Bidisha Das <bd...@runmyprocess.com>:
Hi,
I have checked your code and corrected it.I am sending you the modified code assuming that : id_gerador is the identifier of  your 
autocomplete field on WIID is the name of the field as you have saved in Collection, id is the value variable of the field, id_consulta_geradores_reee is the identifier of your CAPI.

I want you to add one more code in the input variables of your CAPI instead of using connector for that and don't write anything in output variable.

Take a variable: gera_result: <#assign values = []>
                                              <#list query?split(" ") as value>
                                              <#assign values = values +[{"ID": {"$regex" : "^${value}" , "$options" : "i" }}]>
                                              </#list>
                                              <#assign pattern = {}>
                                              <#assign pattern = P_json_put(pattern,"$and",values)>
                                              <#assign result = inject_objects(list_objects(pattern,"Your Collection Name"))>
                                               ${result}

The output of the CAPI would be all the values from collection related to your ID.After that plugin the CAPI to WI and use the code am sending you as attachment assuming that ID is the autocomplete field in your WI. 

Also you can use one CAPI  for autocompleting only one field at a time.If you want to do the same for other fields, follow the same.Create a separate CAPI & use the same code,just replace the variable names.

Hope it helps and for further posts,please post on Support Forum.

Thanks & Regards
Bidisha

DOCUMENTAÇÃO API.pdf

con...@ecotronicbr.com

unread,
Oct 22, 2014, 9:48:22 PM10/22/14
to suppor...@runmyprocess.com, con...@ecotronicbr.com

Hello,

con...@ecotronicbr.com

unread,
Oct 22, 2014, 9:48:59 PM10/22/14
to suppor...@runmyprocess.com, con...@ecotronicbr.com
On Thursday, October 16, 2014 8:42:39 PM UTC-3, con...@ecotronicbr.com wrote:


I send the file in by email.


thoshino

unread,
Oct 22, 2014, 10:56:07 PM10/22/14
to suppor...@runmyprocess.com, con...@ecotronicbr.com
Hi,

I cannot read Portuguese but I hope below will help.

First of all, since the documentation mentions authorization-token, I recommend you do this using Connector and Composite API.
You could write all Javascript (jQuery ajax() for example), but this means anyone who can access the web interface and debug and steal the authentication token. This should be avoided.

So, what you need to do is,
1. Create a new Provider for "Sigecloud".
2. Create Connectors to this Provider.
3. Create Composite API to make API call(s)
4. Attach this Composite API to your web interface and fill in widgets with returned objects.

For #1 and #2, you need to read the documentation and create as specified.
#3 is not absolutely mandatory, you can call Connector itself from web interface, but Composite API will add more control on your side (access rights, input/output scripting).
#4, you can refer to this documentation

I hope this helps.
If you get stuck as some step, please feel free to come back to forum for help.

Best regards,

Taka

ADMINISTRADOR ECOTRONIC

unread,
Oct 23, 2014, 12:02:18 PM10/23/14
to thoshino, suppor...@runmyprocess.com
Hello Taka, 

I did everything that you are saying, but I'm having difficults to write the code to take the values from the json result and consist them in the WI. 

Bidisha wrote a code to solve the problem, but the code uses a collection, and I want to use the result of CAPI.

The CAPI is tested and its working good! I would like to write a code to take the json result from CAPI and consist them in WI, in text input widget. 

Can you help me ?


Best regards. 


Leo   

thoshino

unread,
Oct 23, 2014, 12:26:03 PM10/23/14
to suppor...@runmyprocess.com, thos...@runmyprocess.com, con...@ecotronicbr.com
Hi Leo,

Sure.
What does your CAPI return JSON look like, and what are the fields you want to fill in the data with?

You can set CAPI to Manually launch via Javascript, and make a JS widget that runs the following code (with real variable names of course).

function ok(P_computed){
//When CAPI returns completed status, results will be treated here
    console.log(JSON.stringify(P_computed));
RMPApplication.set("webform_variable_1",P_computed.capi_json_key1);
RMPApplication.set("webform_variable_2",P_computed.capi_json_key2);
RMPApplication.set("webform_variable_3",P_computed.capi_json_key3);
}

function ko(P_error){
    alert(JSON.stringify(P_error));
}

var input = {"input_1":"value_1","input_2":"value_2"};
// input could be: var input = RMPApplication.getAllVariablesValues();

var options = {"mode":"TEST","version":"7347"};
// or simply var options = {}; to execute the composite API in the mode and the version used by the current web interface

id_api.trigger(input,options,ok,ko); //Here, CAPI will launch, and if no error, go to ok function.

Best regards,

Taka
Reply all
Reply to author
Forward
0 new messages