You are not logged in.
Pages: 1
I've been working with GLPI over this week, using an edited version of the old library, available on GitHub.
After some changes, I was able to make it work, and was able to get user information.
Now I want to change the user language by the API. So I made a script to ask him for which language he wants, and then, I send the API request.
var glpi_language = null;
if (language === "en") {
glpi_language = "en_US";
}
try {
console.log("Updating user language");
const response = glpi.updateItem({itemtype: 'User', id: userId, input: {
'17': glpi_language
}});
console.log("User language updated");
console.log(await response.promise);
} catch (error) {
console.error(error);
}
The answer was as expected and I got no error on the request:
1|ChatBot | [ { '10': true, message: '' } ]
The problem is that it does not change the language for the user.
For default my GLPI is in Portuguese, and the user has a null value for Language
1|ChatBot | {
1|ChatBot | user: 'abc.abc',
1|ChatBot | id: 10,
1|ChatBot | active: 1,
1|ChatBot | name: 'abc',
1|ChatBot | cellphone: '+55123456789',
1|ChatBot | language: null,
1|ChatBot | lastname: 'abc',
1|ChatBot | glpi_tickets: 0,
1|ChatBot | titles: null
1|ChatBot | }
And after the API request, the result is the same.
I tried changing the language via the GUI, and it works as expected. It changes the value for language on the API check, as expected.
Is there something wrong in the process? Can I do some specific tests, or look at some logs to check what is going on?
Offline
Can you try using the field name 'langauge' instead of the search option ID '17'?
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Online
Thanks, cconard96.
That's exactly my mistake. Since the ID was used for force display the data, I wrongly assumed I should use it on the filter.
However, I find strange that setting the language to pt_BR it shows as null, I understand that this is the default language, but this way I cannot differentiate a user that is on default for one that has set the language to pt_BR. This is a problem for the way I planned to have it working. Is this the expected behavior? Is there a workaround? In a future, if I decide to change the default Language to en_US, will all of them change, and I'll need to work on this?
Sorry for asking a lot about, but I'm curious on how it should work.
Offline
It is expected to show null if a user has no preference set and it just uses the default. It isn't going to be changed. The current API shows you the data exactly, more or less, as it is stored in the database since it is a low-level API that is a small wrapper around the internal GLPI code.
A higher-level REST API will be coming in GLPI 11. Although, the user preference part isn't implemented yet. When it is, it may be done so that the default options are used when the user has nothing set. No promise it will be done that way or ready for the initial GLPI 11 release.
You can find the initial Pull Request for the new API here with some more details about it versus the current API.
https://github.com/glpi-project/glpi/pull/12221
GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.
Online
Pages: 1