Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAMPO DINAMICO #3486

Open
petrickfreitas opened this issue Apr 3, 2024 · 2 comments
Open

CAMPO DINAMICO #3486

petrickfreitas opened this issue Apr 3, 2024 · 2 comments

Comments

@petrickfreitas
Copy link

Describe the bug
Faço uso do GLPI versão 10.0.14 juntamente com o FormCreator versão 2.13.9. Preciso criar um campo em um dos formulários, para que esse campo consulte uma base externa de clientes. Já pensei em colocar um campo do tipo selecionar e nele colocar a lista de clientes como valores, só que essa base de clientes é atualizada diariamente com aproximadamente 250 clientes por dia, não dar pra ficar fazendo isso manualmente. Criei um arquivo em php, aonde ele faz a conexão com um banco de dados externo via odbc, onde estão os registros dos clientes e me retorna todos os clientes. Esse arquivo salvei no diretório
/var/www/html/glpi/marketplace/formcreator/inc/field com o nome testefield.class.php:

"<?php
$modocon = 'cache32';
$usuario = '';
$senha = '';

$conexao = odbc_connect($modocon, $usuario, $senha);

if (!$conexao) {
exit("Erro na conexão com o banco de dados: " . odbc_errormsg());
}

$query = "SELECT TOP 5 CNPJCPF, codCliente, nome FROM Fat.Cliente WHERE situacao = 1";

$res = odbc_exec($conexao, $query);

$clientes = array();

while ($row = odbc_fetch_row($res)) {
$clientes[] = array(
'CNPJ_CPF' => odbc_result($res, "CNPJCPF"),
'Codigo_Cliente' => odbc_result($res, "codCliente"),
'Razao_Social' => odbc_result($res, "nome")
);
}

if (count($clientes) == 0) {
echo ("0 resultados" . odbc_errormsg());
} else {
echo json_encode($clientes);
}

odbc_close($conexao);
?>"
e no diretório /var/www/html/glpi/marketplace/formcreator/templates/field criei o arquivo com o nome testefield.html.twig:

"



{{ item.label|trans }}
{% if item.isRequired %}
*
{% endif %}

<input type="text"
class="form-control"
id="{{ item.getId }}"
name="formcreator_field_{{ item.getId }}"
value="{{ item.default_values }}"
{% if item.isRequired %} required {% endif %}

"

Quando crio esses arquivos, e acesso o GLPI para adicionar uma nova questão no formulário, só aparece para inserir o nome e a seção, o botão de salvar some, e os demais para colocar o tipo do botão também e etc... Não tendo como criar uma nova questão e nem editar uma já criada. Quando excluo os arquivos volta ao normal. Gostaria de uma ajuda, para saber como poderia resolver esse meu problema de criar um campo no formulário para que consulte uma base. Ou se tiver outra alternativa de fazer isso também, aceito sugestões.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

GLPI / Plugins (please complete the following information):

  • GLPI version
  • list of all plugins with their version (available in GLPI > Setup > General > tab System > bottom of the page)

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@ftoledo
Copy link

ftoledo commented Apr 15, 2024

We working on add custom field too. Any tips will be appreciated

@btry
Copy link
Collaborator

btry commented Apr 16, 2024

Hi

You should chech in php-errors.log and sql-errors.log. You should find errors related to your code.

Your file testefield.php does not contains any class, then it is not good. You should examine dropdownfield and see how it is implemented. Check also the interface PluginFormcreatorFieldInterface and the class PluginFormcreatorAbstractField

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants