I want to remove the value from the custom field or set it to null. The code below is not working as expected. Please advise me.
Thanks in advance.
regards
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def customField = customFieldManager.getCustomFieldObject("customfield_10107");
def value = issue.getCustomFieldValue(customField);
customFieldManager.removeCustomField(customField)
Hi
Try
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def customField = customFieldManager.getCustomFieldObject("customfield_10107")
def value = issue.getCustomFieldValue(customField) //<-- don't know why you wanted this
issue.setCustomFieldvalue(customField, null)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hi Peter,
Thanks for the advice. I have tried with code below, but it still doesn't set the custom field value to null.
Please advise.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.context.IssueContextImpl;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.config.PriorityManager
def customFieldManager = ComponentAccessor.customFieldManager
def userManager = ComponentAccessor.getUserManager()
def issueManager = ComponentAccessor.issueManager
def user = userManager.getUserByName("UserA")
def value = issue.getCustomFieldValue(customField)
MutableIssue mutableIssue = (MutableIssue) mutableIssue.setCustomFieldValue(customField,null)
issueManager.updateIssue(user, mutableIssue, 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.
Perhaps some more detail as to where this code is implemented exactly.
This code seems incomplete.
For example:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the response delay. I have a plan to implement in the post function(Transition stage)
I tried to research and modify the script but no luck. it still is getting an error as below,
1. If function doesn't work
2. cannot set the custom value to null
Thanks,
ERROR [workflow.AbstractScriptWorkflowFunction]: Script function failed on issue: ST-102, actionId: 761, file: null
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldvalue() is applicable for argument types: (com.atlassian.jira.issue.fields.ImmutableCustomField, null) values: [Request participants, null]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)
at Script127.run(Script127.groovy:22)
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.context.IssueContextImpl;
import com.atlassian.jira.issue.fields.config.FieldConfig;
def issueManager = ComponentAccessor.issueManager
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("UserA")
def customFieldManager = ComponentAccessor.customFieldManager
def Participants_Value = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10101"))
def Participants = customFieldManager.getCustomFieldObject("customfield_10101")
def Company_Value = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10107"))
def Company = customFieldManager.getCustomFieldObject("customfield_10107")
if (Company_Value.equals("companyA")){
issue.setCustomFieldvalue(Participants , null)
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.
Ah!
Took me a minute.
Simple typo. It should be setCustomFieldValue not setCustomerFieldvalue
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.