Importing spent time
Added by Domhnall Currie about 4 years ago
I've read what information I can find where this feature was added, but I don't understand how this actually works. I created a .CSV file to try to match what RM is looking to import. It lets me map every field but Project where it makes me choose a project. Is this how this is supposed to work? So every line imported from a given file has to go into one project or is there a way to read the Project field from the .CSV file and each line in the import goes into the appropriate project?
Replies (3)
RE: Importing spent time - Added by Marius BĂLTEANU about 4 years ago
Importing time entries on multiple projects is not supported. You should open a feature request.
RE: Importing spent time - Added by Murilo Habermann Torquato over 3 years ago
Domhnall Currie wrote:
I've read what information I can find where this feature was added, but I don't understand how this actually works. I created a .CSV file to try to match what RM is looking to import. It lets me map every field but Project where it makes me choose a project. Is this how this is supposed to work? So every line imported from a given file has to go into one project or is there a way to read the Project field from the .CSV file and each line in the import goes into the appropriate project?
I did a trick here to allow my internal team to import CSV times from multiple projects.
- created a new customized field "project import" on time entries
- created a new customized field "issue import" on time entries
- create 2 triggers as follows:
CREATE OR REPLACE FUNCTION update_project() RETURNS trigger AS $$ declare import_project_id integer; begin -- only execute the trigger if the field is 73 IF NEW.custom_field_id != 73 THEN RETURN NEW; END IF; raise NOTICE 'import_project: "%" ', NEW.value; -- check if the import_project is not empty IF coalesce(new.value,'') != '' then -- get the project ID SELECT id INTO import_project_id FROM public.projects WHERE identifier = NEW.value; raise notice 'import_project_id: "%"', import_project_id; IF import_project_id = 0 THEN RAISE EXCEPTION 'Projeto (Importação) inválido: verifique o identificador antes de seguir.'; END IF; -- atualiza o ID do projeto para o tempo importado update public.time_entries set project_id = import_project_id where id = new.customized_id; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; ALTER FUNCTION public.update_project() OWNER TO redmine; GRANT ALL ON FUNCTION public.update_project() TO redmine; DROP TRIGGER IF EXISTS update_project ON custom_values; CREATE TRIGGER update_project AFTER insert or UPDATE ON custom_values FOR EACH ROW EXECUTE PROCEDURE update_project(); CREATE OR REPLACE FUNCTION update_issue() RETURNS trigger AS $$ declare import_issue_id integer; import_project_issue_id integer; begin -- only execute the trigger if the field is 74 IF NEW.custom_field_id != 74 or coalesce(new.VALUE,'') = '' THEN RETURN NEW; END IF; import_issue_id := NEW.value::integer; raise NOTICE 'import_issue_id: "%" ', import_issue_id; -- verifica se não houver um valor para a tarefa de importacao IF import_issue_id > 0 then -- grava o valor do ID do projeto da tarefa informada no campo de importacao na variavel import_project_issue_id SELECT project_id INTO import_project_issue_id FROM public.issues WHERE id = import_issue_id; raise notice 'import_project_issue_id: "%"', import_project_issue_id; -- atualiza o ID do projeto para o tempo importado update public.time_entries set project_id = import_project_issue_id, issue_id = import_issue_id where id = new.customized_id; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; ALTER FUNCTION public.update_issue() OWNER TO redmine; GRANT ALL ON FUNCTION public.update_issue() TO redmine; DROP TRIGGER IF EXISTS update_issue ON custom_values; CREATE TRIGGER update_issue AFTER insert or UPDATE ON custom_values FOR EACH ROW EXECUTE PROCEDURE update_issue();
after that, my team is using a spreadsheet for support tracking times during the day and after they can import a CSV (attached as example)
RedmineTimeTracker.csv (1.19 KB) RedmineTimeTracker.csv |
RE: Importing spent time - Added by Domhnall Currie 4 months ago
Thank you for posting this Murilo and the heads-up Marius! I don't know how I missed seeing this! Anyway, it's still relevant as I just came looking for more info on importing issues. :) Marius, I noticed on one of the found items on my search that multiple project imports is now available in 5.something so that's awesome. Thank you for posting that SQL code Murilo as I just started the journey to better implement my RM installation and I just started learning SQL to produce the reports I've been needing. I may not need the code now that RM supports multiple project imports but I'll save it in my knowledgebase as I'm collecting How-To's for my learning. Thanks to both of you for responding!
Pat