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.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems to want a generic value, not a Project object or Double. Have you tried setting it to project.getGenericValue() ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure originalProduct is - I think you want ModifiedValue as you had, but pass in a genericvalue for the new value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getProjectCategory method returns GenericValue object and so i called that. Is that what you ask?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I alerady tried that and the exception is also posted on the actual description of this issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got null and so tried all these ways.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No exceptions this time but still no luck :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Spatruni,
You can use customFieldObject.updateValue() method to update the customField Value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any other comments please?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
find the project picker code at http://forums.atlassian.com/thread.jspa?forumID=46&threadID=28305, i hope it should work for u
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Save the project id instead of saving the entire Project object into the custom field value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the id as String, not Long.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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())
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry mate. I hope someone else knows!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No Probs Jobin. Thanks a ton for your support..
Will wait for any other responses..
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.