Open msm4311 opened 1 year ago
I think that you must use the journal:
issue.init_journal(User.current, 'Your notes')
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
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
From where do you take the object issue? Post your complete code.
Im sorry I don't know ruby, I define the before "saving observable object" on a custom workflow
Then it should be:
self.issue.init_journal(User.current, 'Your notes')
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.
if comments.present?
self.issue.init_journal(User.current, comments)
self.issue.save!
end
works for me.
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?
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...
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 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