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

Adding a Note from time entry comment works on Edit Issue, not on Time Log #301

Open
msm4311 opened this issue Feb 20, 2023 · 10 comments
Open

Comments

@msm4311
Copy link

msm4311 commented Feb 20, 2023

I need to save as issue note the Log Time comments field so I've created a Time Entry custom workflow on before saving:

if comments.present?
issue.notes = comments
end

This works if I enter time from edit link of an issue but it does nothing from Log Time link on same issue.

How can I make it work on both links?

Thanks

@picman
Copy link
Collaborator

picman commented Feb 23, 2023

I think that you must use the journal:

issue.init_journal(User.current, 'Your notes')

@msm4311
Copy link
Author

msm4311 commented Feb 27, 2023

I put on before saving observable object

if comments.present?
issue.init_journal(User.current, comments)
end

But I'm afraid it does nothing, neither on edit link nor Log Time link.

Any idea?

This is my environment:

Environment:
Redmine version 4.2.4.stable
Ruby version 2.6.9-p207 (2021-11-24) [x86_64-linux]
Rails version 5.2.6.2
Environment production
Database adapter Mysql2
Database timezone CEST
ActiveRecord timezone local
App timezone UTC
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery smtp
SCM:
Subversion 1.14.1
Git 2.35.1
Filesystem
Redmine plugins:
custom_field_sql 2.5
custom_tables 1.0.6
periodictask 4.1.0
redhopper 2.0.0
redmine_activity_report 1.2.10
redmine_banner 0.3.4
redmine_closed_date 0.1.1
redmine_custom_workflows 2.0.3
redmine_dashboard 2.12.1
redmine_datetime_custom_field 1.0.4
redmine_issue_sla 2.0.0
redmine_more_filters 1.4.4
redmine_pivot_table 0.0.7
redmine_status_history 1.0.1
redmine_xlsx_format_issue_exporter 0.1.7

@msm4311
Copy link
Author

msm4311 commented Feb 27, 2023

I tried also to put only your sugestion:
issue.init_journal(User.current, 'Your notes')
But when I try to save custom workflow I get this error:
Workflow script executable before saving observable object contains error: undefined method `init_journal' for nil:NilClass

@picman
Copy link
Collaborator

picman commented Feb 27, 2023

From where do you take the object issue? Post your complete code.

@msm4311
Copy link
Author

msm4311 commented Feb 27, 2023

Im sorry I don't know ruby, I define the before "saving observable object" on a custom workflow
image

@picman
Copy link
Collaborator

picman commented Feb 27, 2023

Then it should be:

self.issue.init_journal(User.current, 'Your notes')

@msm4311
Copy link
Author

msm4311 commented Mar 22, 2023

Thanks Picman but I've tried

if comments.present?
   self.issue.init_journal(User.current, comments)
end

and it saves workflow without errors but it does nothing on time from edit link of an issue nor from Log Time link.

@picman
Copy link
Collaborator

picman commented Mar 22, 2023

if comments.present?
   self.issue.init_journal(User.current, comments)
   self.issue.save!
end

works for me.

@msm4311
Copy link
Author

msm4311 commented Mar 22, 2023

Your code:

if comments.present?
   self.issue.init_journal(User.current, comments)
   self.issue.save!
end

works on Log Time Link but not on Edit link on an issue.

My first code:

if comments.present?
   issue.notes = comments
end

is the opposite, works on Edit Link but not on Log Time Link on an issue.

Any idea? If not, is there any way of know in which of the links is executing the workflow to put both code?

@lucascarvlima
Copy link

I'm having the same problem... any idea?

I am using this code on an time_entry before saving script:

nota = ''
if new_record?
  nota = Date.today.to_s + ' - Tempo lançado: ' + hours.to_s + 'h no dia ' + spent_on.to_s + '.'
else
  if hours_was != hours
    nota = Date.today.to_s + ' - Tempo do dia ' + spent_on.to_s + ' editado: de ' + hours_was.to_s + 'h para ' + hours.to_s + 'h.'
  else
    nota = ''
  end
end

if !spent_on.blank? and nota != ''
   i = self.issue
   i.init_journal(User.find_by_id(1), nota)
   i.save!
end

The idea is to save a journal when a time is logged/edited.
It works perfectly when the time_entries page is used...

  • when a time_entry is logged, a journal like '2024-04-01 - Tempo lançado: 6.0h no dia 2024-03-20' is added.
  • when a time_entry is edited, a journal like '2024-04-01 - Tempo do dia 2024-03-20 editado: de 6.0h para 6.1h' is added.

The problem is when the user wants to log a time_entry using the edit issue screen... when that happens, no journal is added, even tho the the time_entry is.

I tried this exception to check if the before_save script is being called when the user does that...

if !spent_on.blank? and nota != ''
   i = self.issue
   i.init_journal(User.find_by_id(1), nota)
   i.save!
   raise RedmineCustomWorkflows::Errors::WorkflowError, nota
end

And the error shows that the variable nota has the correct value... the journal is just not added.

Is there a way to fix this?
I tried to make a second script for the before_save of the issue, but I just can't figure out how to get the hours out of the form.

  • I am using Redmine 4.2.10.stable, and redmine_custom_worflows 2.0.9.
  • Sorry for the broken english.

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

No branches or pull requests

3 participants