Hi Community, Can you help me regarding with my problem?
I have a User Picker Custom Field on Customer Portal, I want it to be default by catching who is the current user and place it on that custom field.
Is it possible using scriptrunner? and on what part of scriptrunner? Scripted Fields? Post Functions? Any help is really appreciated, if you do have some code to start with, that would be great. Thanks!
Hello @Alvin Parreno
You can achieve it via script postfunction. Here code example
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// a user custom field
def userCf = customFieldManager.getCustomFieldObjectByName("User Picker Customfield Name")
def currenrUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(currenrUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
Just a small suggestion, I personally prefer to use
customField.updateValue method to update custom field value on Issue instead of issue.setCustomFieldValue because then the "updateIssue" statement is not required.
void setCustomFieldValue(CustomField customField, Object value)
Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading.
To actually set a custom field value, use
OrderableField.updateIssue(com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem, MutableIssue, java.util.Map)
customField- the CustomField
value- the value.
Postfunction will update field value after issue will be created.
If you want to set value right on portal interface, you can use scriptrunner behaviours.
@Tarun SapraIn my opinion, i would not recommend to use updateValue, because it save changes directly in database and changes will not appear in the issue history.
I think this is really bad practice, when issue changes without saving history. Because when something happens, it will be really hard to find out cause of problem.
def users = getFieldById("customfield_xxxxx)
def currentuser = ComponentAccesor.getJiraAuthenticationContext().getLoggedInUser().getName()
I put it on Initialiser. because I just want to have that user picker field a default value when they are creating a ticket., but still no luck
As i remember, you need to provide key, not name
def users = getFieldById("customfield_xxxxx")
def currentuser = ComponentAccesor.getJiraAuthenticationContext().getLoggedInUser().getKey()
Are you map this behaviour to Service Desk?
Hello @Mark Markov
Indeed, if history changes and other permission(workflow etc) checks are a priority then using the IssueServcie is the safest bet which doesn't violate the permission checks as well unlike the issueManager. updateIssue
Hello @Alvin Parreno
Since you want the value to be populated before issue creation thus Behaviours is the option that comes to my mind as well, can you please try this code
def affectedUser = getFieldByName("<You custom field name here>")
def currentuser = ComponentAccessor.jiraAuthenticationContext.loggedInUser.username
I just tested what @Tarun Sapra posted on Oct 2, 2018 and its working for me. Just a side note, when mapping the behavior to the specific project, be sure to select the Service Desk option as they have split-out the Service Desk and Jira mapping options. I'll also note that the behaviors functionality only recently (within the last year or so) became available on the Service Desk side, I don't remember which version. So it might have been that it only had the Jira capabilities with the version you had installed. But hopefully you have a more recent version now and have it working! Thanks!!
Time (on server): Tue Oct 02 2018 17:29:55 GMT+0800 (+08)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2018-10-02 09:29:54,032 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-10-02 09:29:54,049 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script> java.lang.IllegalArgumentException: Source GenericValue can not be null. at com.atlassian.jira.association.NodeAssociationStoreImpl.getSinksFromSource(NodeAssociationStoreImpl.java:34) at com.atlassian.jira.project.version.DefaultVersionManager.getVersionsByIssue(DefaultVersionManager.java:752) at com.atlassian.jira.project.version.DefaultVersionManager.getFixVersionsFor(DefaultVersionManager.java:598) at com.atlassian.jira.project.version.DefaultVersionManager.updateIssueFixVersions(DefaultVersionManager.java:568) at com.atlassian.jira.issue.fields.FixVersionsSystemField.updateIssueValue(FixVersionsSystemField.java:98) at com.atlassian.jira.issue.fields.AbstractVersionsSystemField.updateValue(AbstractVersionsSystemField.java:368) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:708) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:673) at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:659) at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:214) at com.atlassian.jira.issue.IssueManager$updateIssue$0.call(Unknown Source) at Script978.run(Script978.groovy:10)
Learn how to use two new reports for next-gen projects in Jira Cloud: Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events