Hi,
Using scripted postfunction, I am trying to set the custom fields values but geetign error while doing it.
Gole:
1:Read custom field values form the linked tickets.
2:Update the values of the current main ticket, with as that of the the linked ticket fields.
Script:
-----------------------
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
def log = Logger.getLogger("RS:")
log.setLevel(Level.DEBUG)
try
{
//CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
//IssueManager ism = ComponentAccessor.getIssueManager()
MutableIssue iss = (MutableIssue) issue
def customFieldManager1 = ComponentAccessor.getCustomFieldManager()
def issueLinkManager1 = ComponentAccessor.issueLinkManager
def issueManager1 = ComponentAccessor.issueManager
def currentUser11 = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ParentKey = iss.getKey().toString()
def issue1 = issueManager1.getIssueByCurrentKey(ParentKey)
log.debug("parent Key is: "+ParentKey)
String parent_id = iss.getId()
def application_Clarity_ID_1 = customFieldManager1.getCustomFieldObjectsByName('Application Clarity ID')
def project_Clarity_ID_1 = customFieldManager1.getCustomFieldObjectsByName('Project Clarity ID')
def lst = [];
def newlst = lst.sort();
//def p_id = 27697
def linkMgr = ComponentAccessor.getIssueLinkManager()
log.debug("Issue Link class validated")
List<IssueLink> outwardLinks = linkMgr.getInwardLinks(parent_id as long)
String [] linkedTktplHldr
log.debug("Iterating the Links")
for(IssueLink tempIl: outwardLinks)
{
log.debug("inside for")
log.debug("sanity Check: ")
String issue_link = tempIl.getIssueLinkType().getOutward()
log.debug("Links Are:"+issue_link)
def child_key = tempIl.getSourceObject().getKey()
log.debug("Child Key :"+child_key)
IssueManager ism2 = ComponentAccessor.getIssueManager()
log.debug("Scripted Field call")
def customFieldManager2 = ComponentAccessor.getCustomFieldManager()
def issueLinkManager2 = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//MutableIssue iss = (MutableIssue) issue
def issue2 = issueManager.getIssueByCurrentKey(child_key)
def application_Clarity_ID = customFieldManager2.getCustomFieldObjectsByName('Application Clarity ID')
def application_Clarity_ID_Value = issue2.getCustomFieldValue(application_Clarity_ID)
log.debug("Application Clarity ID: "+application_Clarity_ID_Value)
def project_Clarity_ID = customFieldManager2.getCustomFieldObjectsByName('Project Clarity ID')
def project_Clarity_ID_value = issue2.getCustomFieldValue(project_Clarity_ID)
log.debug("Project Clarity ID: "+project_Clarity_ID_value)
issue1.setCustomFieldValue(application_Clarity_ID_1, project_Clarity_ID_value);
//this piece of code is not working
}
}
catch(Exception e)
{
log.debug("failed to execute"+e)
}
Error:
---------------
Error:
--------------
failed to executegroovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (com.google.common.collect.SingletonImmutableList, String) values: [[Application Clarity ID], 089334]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)
Cancel
Jira version :8.0.2
Hi @rohit sharma your variable application_Clarity_ID_1 is collection of custom fields because you are using this method: https://docs.atlassian.com/software/jira/docs/api/8.0.2/com/atlassian/jira/issue/CustomFieldManager.html#getCustomFieldObjectsByName-java.lang.String-
You can use something like
if(application_Clarity_ID_1 && !application_Clarity_ID_1.isEmpty()){
issue1.setCustomFieldValue(application_Clarity_ID_1.get(0), project_Clarity_ID_value);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Martin,
Yesterday I didn't get time. I will try today and let you know the outcome .
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi martin, with your help the reported issue is fixed. Thanks a lot for the help and explanation.
Thanks,
Rohit
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.