Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with assigning project to a custom field.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

Getting the following exception when trying to update a project custom field with a jira Project.

java.lang.ClassCastException: class com.atlassian.jira.issue.customfields.impl.ProjectCFType passed an invalid value of type: class com.atlassian.jira.project.ProjectImpl

How to update a project custom field with a Jira Project.

9 answers

1 accepted

0 votes
Answer accepted
Renuka Patil
February 28, 2012

Hi Spatruni,

You can use customFieldObject.updateValue() method to update the customField Value.

CustomField project = customFieldManager.getCustomFieldByName("Name of your custom Field");

project.updateValue(FieldLayoutItem arg0, Issue issue, ModifiedValue arg2, IssueChangeHolder issueChangeHolder)


where, FieldLayoutItem can be null or can give value for FieldLayoutItem.

Issue issue = issue object in which you want to update the value of customField.

ModifiedValue arg2 = new ModifiedValue(oldValue of customField, newValue which you want to update)

IssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder()

I think this will work for you.

1 vote
Renuka Patil
March 18, 2012

Hi Spatruni,

old value to modify you can take it as issue.getCustomFieldValue(customField)

new value would be a projectObject.getName().

I think this will work!!!

Regards,

Renu

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 19, 2012

It wont work. because projectObject.getName() returns String but the new value requires reference of type ProjectCFType. I tested and posted the result on this thread long back.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 28, 2012

It seems to want a generic value, not a Project object or Double. Have you tried setting it to project.getGenericValue() ?

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 29, 2012

I tried with GenericValue and found no exception this time but the value is not assigned. Any guess?

originalProduct.createValue(issue, componentManager.getProjectManager().getProjectObjByKey(pKey).getProjectCategory());

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 29, 2012

Not sure originalProduct is - I think you want ModifiedValue as you had, but pass in a genericvalue for the new value.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 29, 2012

getProjectCategory method returns GenericValue object and so i called that. Is that what you ask?

Renuka Patil
March 1, 2012

Hi Spatruni,

I think you will require GenericValue of the project not genericValue of projectCategory. I think instead of GenericValue you should use projectobj.

Regards,

Renu

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 1, 2012

Hi Renu,

I found most of the methods which returns GenericValue are deprecated and so i used getProjectCategory. Pls post if you have any idea about the methods which returns the required.

-Srini

Renuka Patil
March 1, 2012

Hi Spatruni,

As all the methods for project which returns GenericValue are deprecated, I think you will need method which returns Project object.

i.e. projectManager.getProjectObject(Long projectId)

Hope this will work!!!

Try this & do tell me the result!!!

-Renu

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 1, 2012

I alerady tried that and the exception is also posted on the actual description of this issue.

Renuka Patil
March 2, 2012

If you want to update the customField the best way is to use updateValue().

Have you tried using this method? Check what get by this method issue.getCustomFieldValue(customField) if you are getting project key then try to insert project key. If you are getting project name then try to use project name.

Because I have used this updateValue() method everytime I have to update the customField.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 5, 2012

I got null and so tried all these ways.

Renuka Patil
March 11, 2012

If you are gettting null value then you can add condition for it like:

if(issue.getCustomFieldValue(customField) = = null)

{

project.updateValue(FieldLayoutItem arg0, Issue issue, ModifiedValue arg2, IssueChangeHolder issueChangeHolder)


where, FieldLayoutItem can be null or can give value for FieldLayoutItem.

Issue issue = issue object in which you want to update the value of customField.

ModifiedValue arg2 = new ModifiedValue(null, newValue which you want to update)

IssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder()

}

else

{

project.updateValue(FieldLayoutItem arg0, Issue issue, ModifiedValue arg2, IssueChangeHolder issueChangeHolder)


where, FieldLayoutItem can be null or can give value for FieldLayoutItem.

Issue issue = issue object in which you want to update the value of customField.

ModifiedValue arg2 = new ModifiedValue(oldValue of customField, newValue which you want to update)

IssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder()

}

Try it & let me know.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 13, 2012

No exceptions this time but still no luck :(

Renuka Patil
March 18, 2012

Hi Spatruni,

Can you please elaborate more what is happening. If you could tell more about your customfield? Can you please tell which value you are inserting by updating the customfield.

Regards,

Renu

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 18, 2012

Hi Renu,

ModifiedValue arg2 = new ModifiedValue(oldValue of customField, newValue which you want to update)

Not sure how to get the ProjectCFType object reference for the newValue to update.

0 votes
Renuka Patil
February 28, 2012

Hi Spatruni,

You can use customFieldObject.updateValue() method to update the customField Value.

0 votes
srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 27, 2012

Any other comments please?

0 votes
Renuka Patil
February 23, 2012

Hi Srinivas,

You can use

CustomField.updateValue(FieldLayoutItem arg0, Issue issue, ModifiedValue arg2, IssueChangeHolder)

Because, issue.setCustomFieldValue()

Sets a custom field value on this Issue Object, but does not write it to the database.

You can use updateValue!!! It worked for me.

Regards,

Renu

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 24, 2012

Appreciate if you could explain a bit more about the parameters for the updateValue method since i dnt have any references for them in my code.

The below code is working for me but i am getting problem only when updating project custom field.

resolver.createValue(issue, issue.getProjectObject().getLeadUser());

issue.setCustomFieldValue(resolver, issue.getProjectObject().getLeadUser());

0 votes
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 23, 2012

find the project picker code at http://forums.atlassian.com/thread.jspa?forumID=46&threadID=28305, i hope it should work for u

0 votes
srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

I guess this requires ProjectCFType object as parameter but i donno how to get a refeference of that type. Tried in various ways for getting the ProjectCFType referecne but not found the reference. Could someone tell me how to get a ProjectCFType reference for a project or suggest if there is any other alternative way for saving a project information in to a custom field?

Thanks in advance..

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

Save the project id instead of saving the entire Project object into the custom field value.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

Getting the following exception with id.

java.lang.ClassCastException: class com.atlassian.jira.issue.customfields.impl.ProjectCFType passed an invalid value of type: class java.lang.Long

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

Try the id as String, not Long.

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

Hi Jobin, The result is same, classcastexception again.

CustomField originalProduct = componentManager.getCustomFieldManager().getCustomFieldObject("customfield_10031");
originalProduct.createValue(issue, String.valueOf(componentManager.getProjectManager().getProjectObjByKey(pKey).getId()));

java.lang.ClassCastException: class com.atlassian.jira.issue.customfields.impl.ProjectCFType passed an invalid value of type: class java.lang.String

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

I guess this requires ProjectCFType object as parameter but i donno how to get a refeference of that type. Tried in various ways for getting the ProjectCFType referecne but not found the reference. Could you tell me how to get a ProjectCFType reference for a project or suggest if there is any other alternative way for saving a project information in to a custom field?

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

For one last time, Can you try it as a Double value? Instead of String? This is what the Source has:

new Double(project.getLong("id").longValue())

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

I got the following exception again..

java.lang.ClassCastException: class com.atlassian.jira.issue.customfields.impl.ProjectCFType passed an invalid value of type: class java.lang.Double

Even tried in other way of setting like below but there is no exception and the value is also not updated.

issue.setCustomFieldValue(originalProduct, new Double(componentManager.getProjectManager().getProjectObjByKey(pKey).getId().longValue()));

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

Sorry mate. I hope someone else knows!

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 22, 2012

No Probs Jobin. Thanks a ton for your support..

Will wait for any other responses..

Suggest an answer

Log in or Sign up to answer