In a Webwork action class, in the submit action, I want to programmatically create a CustomField and save some value in it. I have the value which I get as part of a post. Now I want to save it so that I can access the value of this custom filed where I have access to issue. I dont display this filed on the page. Here is the code I tried but its not saving the value.
String videoLink = (String) parametes.get("videos"); CustomFieldType fieldType = customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:textfield"); videoField = customFieldManager.createCustomField("videos", "Video link", fieldType , null, null, null); videoField.createValue(getIssue(), videoLink); videoField.store();
What am I doing wrong here?
According to your actual requirements it sounds you are integrating Jira with a third party application. Supposing you are developing for Jira5 consider changing from customfield development to "JIRA Remote Issue Links" as it is explained at https://developer.atlassian.com/display/JIRADEV/JIRA+Remote+Issue+Links.
You do realise that creating a custom field like that will add it to EVERY issue in your system? Ok, you are only populating one issue with any data, but the whole principle sounds wrong to me - if a user uses your webwork action 20 times, you'll end up with 20 new custom fields.
Even if that really is what you intend to do, it would help if you told us what error message you get (if any), what happens when you add the field to a screen so you can check the value, what the administration screens tell you about the new field you've created and so-on!
Let me give you a bit of background of my requirements,
I have created popup page which can be opened clicking a menu item I have added on the View Issue page. This popup page shows a list of video links, the user should be able to select any one on the link and save it as an attachment. Since, I dont have a file to attach, just a url to a video, I can not save it as an attachment.
So, what I thought is that, I would take the seleted link and save it in a custom filed with the current issue. I would later need to acces this custom filed, take the url, and try to embed the video the url points to, on the View Issue page, preferebly in the attachments section . Am I thinking it wrong? Is there any better way to implement my requirement?
When my code, I posted above, executes, I dont get any error. I am using the following code to retrieve the saved value:
CustomFieldType fieldType = customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:textfield"); videoField = customFieldManager.createCustomField("videos", "Video link", fieldType , null, null, null); log.info("CustomFieldValue" + issue.getCustomFieldValue(videoField));
So, let me get this clear (apologies for the extra questions - I often jump to incorrect conclusions and find that I should really ask more often to make sure I'm talking about the right thing).
1. You don't want to add a new custom field. You want to add (or update) data in a single, pre-existing custom field?
2. This custom field needs to do things that the current custom field types you have available do not support what you need (e.g. a plain text field would just show a url as plain text)?
As an aside, your admin screen shot shows part of the problem - you've got a set of duplicate fields all called videos, but they're not configured to be used anywhere. Duplicate names definitely will cause you problems, and I really don't think you want multiple "videos" fields, but the main thing here is that the fact that they're not configured for any context is why your code is never executed...
I am guessing here, but I'm not sure that you understand the difference between a "custom field", a "custom field type" and a "custom field value" - could you explain? I offer my humble apologies if you do know the difference, but from what I'm seeing, you're uncertain.
First of all let me tell you, I am new to Atlassian plugin development, so, I might have written/asked confusing question.
2. The way I wanted to implement it, I just need to save a URL text in the custom filed.
Let me explain what I understand with those terms and please correct me if I am wrong:
Custom Field: Having an extra input field which Jira does not have.
Custom Field Type: What kind of data the filed will accept and save. The type of the input field, e.g. text, number, binary data.
CustomFieldValue: The actual data that is saved in a custom filed.
The following are my actual requirements:
(1) I want to create a popup/dialog page which would show a list of videos created in a external site. This popup will be tied with a View Issue page menu item.
(2) Users will be able to see the preview of the selected video link on the same popup.
(3) Users will be able to select any of the video link and save it as an attachment.
(4) The attached video link will be shown as an embedded video in the Attachments section of the View Issue page.
Probably I have gone about implementing it in the wrong way. Please suggest me the true path :-)
Ok, that's nice and clear.
The problem you have got is that your code is creating new "custom fields" and it actually wants to be creating "custom field values". You don't want a new custom field each time someone uses the link, you just want a single custom field, which is then populated for issues as they need a video added.
The custom field type is what you need to do, and those are provided by plugins. My suggestion would be
Some minor points about this
Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...
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!
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