You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2018-03-23 10:41:40

dormaich
Member
Registered: 2018-03-23
Posts: 3

notes not saved in computer when based on a template which have notes

Hi everyone,

can anybody help me to find out why notes in asset templates not working? I would like to have a note field in a template that should be set to any created computer based on this template. I can save the note in the template, thats works fine. I can see the note when i create a new computer but when i save the new computer based on the template, all informations are saved but only the notes are missing.

Does anyone have the same problem and solved this?

Thanks for help.

Offline

#2 2018-03-23 16:53:53

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,278

Re: notes not saved in computer when based on a template which have notes

For which version of GLPI?
For which object?


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#3 2018-03-24 17:03:20

dormaich
Member
Registered: 2018-03-23
Posts: 3

Re: notes not saved in computer when based on a template which have notes

Sorry,

i forgot. I have updated glpi from 9.2.1 to 9.2.2. In both Versions is the same issue. I want to save the note to the computer object. Or want do you mean with object?

Thanks.

Offline

#4 2018-03-27 09:20:47

dormaich
Member
Registered: 2018-03-23
Posts: 3

Re: notes not saved in computer when based on a template which have notes

Hi @all,

i have solved this problem by myself. It is only a workaround, so i hope this issue would be fixed in other versions. For all of you which have the same issue, here my solution.

I wrote a trigger in the glpi mysql database for the table "glpi_computers". The Trigger makes after an insert to the computer table an another insert in the notes table with an reference to the new created computer. Before it makes an insert, the trigger checks if the computertemplate has notes. If notes exists in the computertemplate it will iterate through the template notes and save them as new notes with an reference to the new computer.

Here is the Code:

CREATE DEFINER=`USERNAME`@`localhost` TRIGGER `glpi`.`glpi_computers_AFTER_INSERT` AFTER INSERT ON `glpi_computers` FOR EACH ROW
BEGIN
    DECLARE v_itemtype VARCHAR(255) DEFAULT 'Computer';
    DECLARE v_timestamp DATETIME DEFAULT NOW();
    DECLARE v_note TEXT;
    DECLARE v_notecount INT(11);
    DECLARE v_done TINYINT DEFAULT FALSE;
    
    DECLARE c_notes CURSOR FOR SELECT
         glpi_notepads.content
    FROM
        glpi_notepads
    JOIN
       glpi_computers ON glpi_notepads.items_id=glpi_computers.id
    WHERE
       glpi_computers.is_template=1
    AND
       glpi_computers.template_name=NEW.template_name
    AND
       glpi_notepads.itemtype=v_itemtype;
                                
    OPEN c_notes;
    SELECT FOUND_ROWS() INTO v_notecount;
    l_fetch_data: LOOP
		FETCH c_notes INTO v_note;
        IF v_done THEN
			LEAVE l_fetch_data;
            CLOSE c_notes;
        END IF;
        
        IF v_notecount > 0 THEN
			INSERT INTO
				glpi_notepads
					(itemtype, items_id, date, date_mod, users_id, users_id_lastupdater, content)
			VALUES
					(v_itemtype,NEW.id,v_timestamp,v_timestamp,NEW.users_id_tech,NEW.users_id_tech, v_note);
		END IF;
    END LOOP l_fetch_data;
END

Hope this helps.

Last edited by dormaich (2018-03-27 09:23:41)

Offline

#5 2018-04-04 16:43:54

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,278

Re: notes not saved in computer when based on a template which have notes


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

Board footer

Powered by FluxBB