Can i update custom field value of Parent Link type via workflow?

Hi,

 

i'm trying copy value of a custom field to another custom field, this another is a Parent Link custom field. 
I tried of 2 methods: 
1) i tried a copy value of custom field to another custom field using post function, no success...

2) same method, but using sample groovy with updateCustomFieldValue()

using this code: 

def issue = ComponentAccessor.getIssueManager().getIssueObject("T-7665") as MutableIssue
def cfEpicLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(13982L)
def cfParentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(23280L)

def changeHolder = new DefaultIssueChangeHolder();
cfParentLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfParentLink), cfEpicLink.getValue(issue)),changeHolder);

 

I got the same error using this 2 ways. Check Out

 

2017-06-16 18:59:18,552 WARN [common.UserScriptEndpoint]: Script console script failed: java.lang.ClassCastException: com.atlassian.jira.issue.IssueImpl cannot be cast to com.atlassian.rm.jpo.env.issues.SimpleIssueAttributes at com.atlassian.rm.jpo.customfields.parent.ParentCustomFieldType.createValue(ParentCustomFieldType.java:17) at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:692) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:409) at com.atlassian.jira.issue.fields.ImmutableCustomField.updateValue(ImmutableCustomField.java:395) at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)

Is impossible to do this or have a way ?

Gratz

1 answer

1 vote
Steven Behnke Community Champion Jun 16, 2017

It's very possible. You're trying to push a round peg into a square hole though. That's why you're getting a Class Cast Exception.

I'm not sure, you should log the values so you can get a better idea of what's happening. It appears that Epic Link field from JIRA Software accepts/returns an IssueImpl object. However, this contrasts with the Parent Link from Portfolio: This field accepts/returns a "SimpleIssueAttributes" object.

You'll have to figure out how to map between the two of them yourself. If you post some results of logging the values of the objects, perhaps I can help more.

Thanks for asnwer Steven

I managed via rest, after so many attempts it was.

 

Thanks for attention anyway

Hi Steven, Jonas,

I have the same problem, but it seems like I am not able to solve that problem on my own :(.

I can't find any documentation about the SimpleIssueAttributes class and so, I am not able to find out the way to cast correcty... 

Jonas, how did you solve this via rest?

We want to use different issuetypes for different departments and I want to make it as easy as possible to use the issues and Portfolio so there can't be any excuses for not using it.... ;)

Would be great if you have an advice or something...

Regards

Katya

 

Hi Katya, 

I relied on this documentation, where we talk about the update custom field via rest. Look at my code that solved the problem. 

Check this documentation: https://docs.atlassian.com/jira/REST/cloud/

import groovy.json.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseException
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def newParentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(0000L) <- here is ID custom field what u have to update.
def jsonObj = new JsonSlurper().parseText('{ "fields": { "customfield_23280": "'+newParentLink+'"} }') //customfield_23280 is Parent Link ID
def parentLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(23280L) <- id parent link custom field

def userName = "user"
def password = "password"
def fullAddress = "youadress/jira/rest/api/2/issue/${issue.key}"
def authString = "${userName}:${password}".getBytes().encodeBase64().toString()

def client = new RESTClient(fullAddress)

try{
//necessary to overwrite the value of custom field, via rest only update if custom field have value null.
parentLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(parentLink), null),new DefaultIssueChangeHolder())
client.put(path: fullAddress,
contentType: groovyx.net.http.ContentType.JSON,
body: jsonObj,
headers: [Accept: 'application/json', Authorization: "Basic ${authString}"]
)
}catch(final HttpResponseException e){
log.warn e
}

i hope this helps you get the solution. 

Good Luck :)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

168 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you