Hi!
I try run this script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
MutableIssue issue
Issue issueIM = issue
CustomField technolog = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("name customfield")
def value_a = technolog.getValue(issue)
def assignee = issue.getAssigneeId()
if(value_a == null ||value_a == ""){
technolog.updateValue(null, issue, new ModifiedValue(null, assignee), new DefaultIssueChangeHolder())
}
else {
issue.setAssignee((ApplicationUser)value_a)
}
We need the assignee field value to be copied to the custom field in case the custom field is empty.
But script don't work.
Regard
Hello @Alexander
This is not right in your code
def value_a = technolog.getValue(issue)
To get the customfield value you should use issue.getCustomFieldValue
def value_a = issue.getCustomFieldValue(technolog)
Also, to update issues you should always use IssueService
https://developer.atlassian.com/server/jira/platform/performing-issue-operations/
Hi @Tarun Sapra
Thanks for your reply
If a custom field has a value, the Assignee field accepts it.
However, the Assignee field does not take a custom field value.
I guess error in this line:
technolog.updateValue(null, issue, new ModifiedValue(null, assignee), new DefaultIssueChangeHolder())
Error log:
java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.user.ApplicationUser at com.atlassian.jira.issue.customfields.impl.UserCFType.getDbValueFromObject(UserCFType.java:83) at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.createValue(AbstractSingleFieldType.java:138) at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:410) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:396) at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source) at Script1176.run(Script1176.groovy:20)
Sorry, I'm new to this.
Regards
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.
Then you should save the ApplicationUser object instead of string in the custom field updateValue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want it:
Copy the user from the Assignee field to the custom field "technolog" (replacing value).
This method does not work :
technolog.updateValue(null, issue, new ModifiedValue(null, assignee), new DefaultIssueChangeHolder())
Help edit please...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to know @Alexander that it works, please accept/upvote the answer so that others are helped as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You did not understand me. The value of the assignee field is not copied to the custom field (technology).
I need to fix this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, & as I have already told you, please create an ApplicationUser object from the assignee.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Alexander
Along with the changes which I have shared already, just change your code from
def assignee = issue.getAssigneeId()
to
def assignee = issue.getAssignee()
And it should work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexander, Can you please provide us more details on what is the error you are getting, which add-on using and your JIRA version.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jira v7.3.7
ScriptRunner Version: 5.4.12
error log:
2018-09-21 12:14:26,347 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-09-21 12:14:26,347 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: PB-441, actionId: 331, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.customfields.impl.AbstractSingleFieldType.getValueFromIssue(AbstractSingleFieldType.java:71) at com.atlassian.jira.issue.fields.ImmutableCustomField.getValue(ImmutableCustomField.java:350) at com.atlassian.jira.issue.fields.CustomField$getValue$3.call(Unknown Source) at Script921.run(Script921.groovy:15)
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.