Hello all,
I want to copy the assignee to a text field custom field. I did the normal way but it is taking just ID with the JIRA userID. I want to get the name with hyperlink. Is this achievable?
Thanks for the help
Hi, @Harsh
Text field must be with wiki markup, and you need to use template like [~username]
Hello @Evgenii
Thanks for the response.
Right now I'm taking the assignee from issue.currentassignee and then just substituting that to the text field(which is description, system field by jira). I think description is wiki markup by default?
Brief code
Def assignee = issue.getcurrentassignee
Def description (system field) = 'text' + assignee.
But what is happening is in description it's is taking the ID and jira assigned username, but i need the link (assignee) or just the iD of the user.
Thanks for the help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Got it. Try next script:
String username = issue.assignee.username
String description = "dummy text" + "[~${username}]"
issue.setDescription(description)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
Unfortunately it throws error on String username
I did for the display name using -
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Harsh
Have you tried getting username with next code?
def username = sourceIssue.assignee?.username.toString()
.username - is standard attribute for user object, that retyrns string with username.
As for adding it into text - the main idea is, that you have to add username between [~ and ]. It generates hyperlink to user profile. Something like this can help:
def description = "text " + "[~" + username + "]"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
Will the code in last comment which mentioned.
Quick question - let's say i have username - X123 and my display name is Harsh. Will the code take in the username or the display name?
I want the display name to Linked in the description. Will update you once i test.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
to mention user you have to use username, but when you'll look at issue, you will see display name.
For example, difference between editor mode and after editing, when you look at description:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
It worked like a charm. Thanks a lot. :) I have accepted the answer.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
Follow up question
can we do the same for 'Single select' field to text field(desc).
I am using this -
def CF = customFieldManager.getCustomFieldObjectByName('CF')
def cfVal = issue.getCustomFieldValue(CF).toString()
def desc = 'text' + cfval
Is this the correct approach?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Harsh if you want to add value, as single text string - it will work.
If you want to add value, as URL, for example, you'll need to wrap value in []
It will look like:
def desc = 'text' + [Link Name|cfVal]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
Not as a link in this case.
Just want value from Single select field (whatever value is selected) to description - 'text'.
But unfortunately it is not picking the value from the single select field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, missed that it's single select field. Mistook it with text field.
Try:
def cfVal = issue.getCustomFieldValue(CF).value.toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I tried it already, but it is returning 'Null' value, but I have selected some value there.
Error - 'Cannot get property 'value' on null object'
Can we get the field by 'getcustomfieldbyID' ? or any workaround.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to select customfield by ID you can use such code:
Use your actual fieldId instead of 12345
def CF = customFieldManager.getCustomFieldObject(12345)
def cfVal = issue.getCustomFieldValue(CF).value.toString()
def desc = 'text' + cfval
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
above already tested, not working. :(
Will combine component accessor and may be it works.
Update - Tried with component accessor as well, its Not working
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, for the suggestion
If you want to select customfield by ID you can use such code:
Use your actual fieldId instead of 12345
def CF = customFieldManager.getCustomFieldObject(12345)
def cfVal = issue.getCustomFieldValue(CF).value.toString()
def desc = 'text' + cfval
I am getting the same error, Cannot get property 'value' on null object'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Don't know, what exactly you're using for testing, made +/- universal script, maybe it can help you to understand where is problem. It must print selected value from custom field in issue. I tested it in scriptrunner.
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.fields.CustomField
CustomField customFieldObject = ComponentAccessor.customFieldManager.getCustomFieldObject(12345)
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1") as MutableIssue
LazyLoadedOption cfValue = issue.getCustomFieldValue(customFieldObject)
log.warn(cfValue.value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Tried this on console, but it still returns null. The single select field has Test-1 value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Press Logs :)
log.warn outputs messages to Logs tab.
Can you make a screenshot of console screen with code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oh shoot my bad.
yes, it is showing. But dont know in post function it is not working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If it's on creation transition, try to add postfunction after issue is reindexed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
even after reindexing the whole issue and project. It is not working.
Still shows the error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you show workflow transition with postfunctions?
Of course, if it's not prohibited by security rules
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is prohibited.
But it just the same code which you sent. Just with the actual customfield ID.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, one more variant of postfunction (it's not for console use). If it won't help, I fail to understand what's the reason of such behaviour:
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
CustomField customFieldObject = ComponentAccessor.customFieldManager.getCustomFieldObject(12345)
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() as ApplicationUser
MutableIssue issue = issue as MutableIssue
LazyLoadedOption cfValue = issue.getCustomFieldValue(customFieldObject) as LazyLoadedOption
String description = "Value from custom field: ${cfValue.value}"
issue.setDescription(description)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Evgenii
Sadly, does not work. It throws the same issue.
But that's not a problem. Will leave it for now, if it works with some other way will update you.
Thanks for all the time and help.
Have a great day.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Evgenii
The issue got resolved.
I used sourceIssue instead of issue. In below line.
def cfVal = sourceIssue.getCustomFieldValue(CF).value.toString()
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Harsh
So, the problem was in sourceIssue. It's weird, but great, that you resolved it! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.