Hi,
I have the script below
CustomField request_type1 = customFieldManager.getCustomFieldObjectByName('Cabling') CustomField request_type2 = customFieldManager.getCustomFieldObjectByName('Airport') CustomField request_type3 = customFieldManager.getCustomFieldObjectByName('ID') String[] list1 = [request_type1, request_type2, request_type3] String[] list2 for(int i = 0; i < list1.length; i++){ list2[i] = targetIssue.getCustomFieldValue(list1[i]) } for(int i = 0; i < list1.length; i++){ issue.setCustomFieldValue(list1[i], list2[i]) }
But I am getting the error..
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImp1.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Cabling]
This is being run as a post function using scripted post function. Create a subtask.
Any help greatly appreciated...
Community moderators have prevented the ability to post new answers.
IMO you would be far better off creating a list of field names and then looping over that. I didn't test this code but I use something similar all the time.
def myFieldList = ["Cabling","Airport","Id"]; for (myFieldName in myFieldList ) { def tempCF = customFieldManager.getCustomFieldObjectByName(myFieldName ); def tempVAL = targetIssue.getCustomFieldValue(tempCF ); issue.setCustomFieldValue(tempCF , tempVAL ) }
Thanks! I'll give this a try.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can confirm with a bit of tweaking this works Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great. I was about to comment that you mentioned bringing values over from a different issue and different projects... this can get troublesome for select lists unless both projects use the same field context. So just keep that in mind should you start to copy drop down lists. You might have to start retrieving the option from from one issue, pulling out the text value (hope that both contexts have that text value!) and then looking up that text value in the other project to get the new option.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Luckily they're using the same field contexts so not having an issue, but I did realise that field configurations have to be set to "Global", even if both projects you're working on are defined. I'll keep your comment in mind though however! Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sy,
Assuming that the Cabling is a custom field of type Select List (which return to you a list) the way to get the values are
def request_type1 = customFieldManager.getCustomFieldObjectByName('Cabling') def listOfValues = targetIssue.getCustomFieldValue(request_type1)
or
cfValues['Cabling']?.value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Cabling is a text field, and not a select list, all I am trying to accomplish is moving the data of Field A from one issue to another.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can I ask how you retrieve the targetIssue ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also try to replace the String[] with def
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the target issue stored in a text field which is def cf = cfValues['Target Issue'] then.. //More Definitions def issueManager = ComponentAccessor.getIssueManager() //Retrieving Target Issue def targetIssue = issueManager.getIssueObject(cf)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As both Nic and Gabrielle mentioned the issue is with the definition, try to replace with def instead of types declaration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks thanos this helps with the select list retrieval.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As I see it list1 is an array of "Custom Field", which is not a String hence the error.
You should get the CustomField name (which is a String) first.
Reference: (https://docs.atlassian.com/jira/latest/com/atlassian/jira/issue/fields/CustomField.html#getFieldName--)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Do you mean something like String getFieldName('Cabling')? etc?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I suspect that your fields are select list type fields? They take/return "options", not strings, so you need to convert the string into an option
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, The issue isn't because of a select list type (even though its a text box), this is because if I do something like: CustomField request_type1 = customFieldManager.getCustomFieldObjectByName('Cabling') def request1_value = targetIssue.getCustomFieldValue(request1) issue.setCustomFieldValue(request_type1, request_value1) then all works fine, whether it is a text box.. multi check box.. etc. I assume it is something to do with my array declaration more of, but not sure
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oh, hang on, your original code is taking a customfield object and wedging it into an array of strings. That's never going to work. This new code works fine because you're getting the value of the string held in the Cabling field and then setting it back. Which seems somewhat pointless, but it's using the right objects, so it's a start. I'm confused as what you're trying to do now!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Basically I'm trying to create a better performing code, the above works fine for me to add everything line by line, but I'm trying to reduce the code so that instead of having multiple: targetIssue.getcustomFieldValue issue.setcustomFieldValue I can instead have two loops that do this instead. My coding isn't the greatest, so would you know how I could get around this issue? I'm not sure as to what to do next, as I've tried declaring it as a Object: Object[] list1 = new list1 [......] But doesn't like it. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, I meant the goal of the script - at the moment, it looks like the aim is to take a value from a custom field and put the same value back into the same custom field. So the optimal code would really be "do nothing"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Haha.. Yes if only "Do nothing" was an option - Its basically taking field values from a different issue in a different project and bringing it into this subtask.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.