Update Message field on view screen during workflow transition

Kevin Seery October 3, 2019

Hi,

I would like to update a Message field on the view screen of an issue. When the issue transition from one status to another. I would like to use HTML and add information from some of the issues fields. 

I would be grateful of any help as I have spent a lot time trying get this working.

We have the following add-on

Script runner, JMWE, CF++

I have tried using

- using a standard jira comments field with wiki formatting 

- JIRA message field
- Script runner message field 

But can't seem to get them to update during the transition?

I not great a script, if you any examples that would be great.

Many Thanks
Kevin

2 answers

0 votes
Deniz Oğuz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2019

Hi Kevin,

We have a sample code for setting content of Message++ field using ScriptRunner in our wiki. You can email to me if you need further information.

0 votes
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2019

Hi @Kevin Seery 

You can create a Text Field (read only) and use the following code in the ScriptRunner's Script Post-Function on your transition.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue


//get the value of Message Field
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectsByName("Message Field")
def cFieldValue = issue.getCustomFieldValue(cField[0])

//Prepare the message with system field or custom message
def message = "*Issue status*: " +
issue.getStatus().name + "\n" +
"*This is a message*"

//update the value
def changeHolder = new DefaultIssueChangeHolder()
cField[0].updateValue(null, issue, new ModifiedValue(cFieldValue, message),changeHolder)

In the code as you can see I am retrieving issue status and also custom field value. You can retrieve any system field or custom field value and prepare your message which you can then update in the message field that you want to display on the issue

For HTML, it is a bit tricky as I am using wiki style renderer which I suggest you try if you just want to try basic editing.

I hope it helps.

Ravi

Kevin Seery October 4, 2019

Hi Ravi,

 

Thanks for replying, I was hope to use HTML so I could get the format I wanted.

Many Thanks

Kevin

Douglas Johnson March 2, 2022

Ravi, your solution to update a read-only field is perfect for my needs. Thank you!

Like Ravi Sagar _Sparxsys_ likes this
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 2, 2022

Good to know.

Suggest an answer

Log in or Sign up to answer