Hi all,
I hope someone can help. Here is what we are trying to accomplish. I was asked to make the field Components selectable based upon a custom field value called product.
Here was my proposal:
Everything works except 3. I have tried a basic copy, then I tried Update Issue Custom Field with the following values:
Try2: ${issue.customfield_13502.toString()}
Try3: ${issue.cfValues['product-component']*.value} or ${issue.cfValues['customfield_13502']*.value}
Try4: ${issue.getCustomFieldValue(getCustomFieldObjectByName("customfield_13502"))}
Try5: ${issue.getCustomFieldValue("customfield_13502")}
try 6: ${issue.getCustomFieldValue(customfield_13502)} or $issue.getCustomFieldValue(product-component)
try 7: ${issue.product-component} or ${issue.customfield_13502:1}
None of which worked
Does anyone know how I could get the value from the top part of a cascading select list called product-component (customfield_13502) into another select list custom field? I will ensure that the first part of product-component has exact values of the customer single select list called product.
Thanks!!!
Robert
You can instead use JMWE's "Set Field Value to Constant or Groovy Expression" post-function with a simple Groovy script:
import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("<name of your cascading field>"); def value = issueObject.getCustomFieldValue(customField); return value?.get(null)?.getValue();
I didn't test this code so there might be an error in it but you get the gist.
Note that the script uses the "issueObject" variable, which is an instance of JIRA's Issue interface.
Wow that did it!!! THANK YOU!!! We are good the exact script above (with the obvious replacement of the name of the cascading field worked perfectly. Case closed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David _old account_ , I want to use your code (I'm completely new to Groovy) for solving my problem:
I have cascading custom field and 2 single custom fields. I want to copy the parent part of the cascading to one custom field and the child part to the other custom field. I followed the steps of initiator Robert and succeeded in copying the child part to the other custom field.
For the parent I want to use your code, but I don't understand where to put the name of the cascading (parent) and where the name of the custom field copying to. Can you help me please? Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sandra,
which app are you using (JMWE or ScriptRuner)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer, We have scriptrunner, but I have no experience in coding (groovy?). We don't have JMWE. Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @David Fischer [Innovalog], could you help me on my question? I want to copy the parent part of a cascading field to a custom field. I don't have JMWE, but use the Scriptrunner post function and copied your piece of coding you mentioned earlier and filled in the name of my cascading field:
import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Projectcode for Hosting"); def value = issueObject.getCustomFieldValue(customField); return value?.get(null)?.getValue();
It gives me an error on the 4th and 5th line of coding saying "The variable [issueObject] is undeclared". My fieldname is correct. It would help me a lot.
Thank you and kind regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sandra Meessen unfortunately, I have zero experience with ScriptRunner. But my guess is that you just need to replace "issueObject" with "issue".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Each option in JIRA customfield has an optionID. You have two fields product-component and product, both are select lists. So you to get the correct option ID for product field and set the value to that. Here you are trying to set the same value which wont work, as it is option for product-component field.
For getting the option for the field you can use
customField.getRelevantConfig(issue)).getOptionForValue("option", null)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Vijay! I appreciate the help... What post function should I use with the above?
Actually product-component is a cascading select and product is a regular select. The above "option" is the product-component ID. IE product-component is also customfield_13502, going into each option also give me an ID, but that is what I am looking for. so here is what product-component returns: linux-gui, linux-installation, windows-interface, windows-installation, windows-bsod, etc. What I am looking put in the product field is linux or windows. As product is a single select list with Linux and Windows as the options.
So is the "option" above the option ID from the customfield (13502) or the option ID (the ID of linux-interface for example)?
Excuse my novelty, but I am trying to write a post function, not a plugin, though one day I hope to get there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would use a script post function and put a groovy script to do this.
Look for the optionID for value "Linux" for the field "Product"
cfProduct.getRelevantConfig(issue)).getOptionForValue("Linux", null)
Below answer will be helpful if you are new to groovy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe I understand the confusion here. I am first just trying to return the value of Product-component to a text field for now, as I cannot even seem to get the value of the multiselect field. If I can get the value of Product-component, setting the field, I think, will be the easy part.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What my question should be I guess is how do I print a string of the parent value of a cascading select list. Here is my sample code I have tried many different samples found on the web/answers none work.
import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.customfields.view.CustomFieldParams import com.atlassian.jira.issue.customfields.option.Option Issue issue = issue; ComponentManager componentManager = ComponentManager.getInstance(); CustomFieldManager customFieldManager = componentManager.getCustomFieldManager(); CustomField customField = componentManager.getCustomFieldManager().getCustomFieldObjectByName("product-component"); Object productValue = issue.getCustomFieldValue(customField)?.getValue(); CustomFieldParams params = (CustomFieldParams) productValue; if (params != null) { Object parent = params.getFirstValueForNullKey(); Object child = params.getFirstValueForKey("1"); } String retVal = parent.toString(); return retVal
Here is the error I usually get:
Error while executing SetFieldValueFunction: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.innovalog.jmwe.IssueProxy@19c983b3' with class 'com.innovalog.jmwe.IssueProxy' to class 'com.atlassian.jira.issue.Issue'
or
/secure/QuickCreateIssue.jspa [jmwe.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [product-component]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below script works. It gives you parent and child as option. You can compare the parent option and then get the valid optionId for the "Product" field
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.fields.CustomField Issue issue = ComponentAccessor.getIssueManager().getIssueObject("DELDEFECT-3922"); CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Cascade"); Map<String, Option> params = (HashMap<String,Option>) issue.getCustomFieldValue(customField) if (params != null) { Option parent = params.get(CascadingSelectCFType.PARENT_KEY) Option child = params.get(CascadingSelectCFType.CHILD_KEY) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much for your help this is really got me beating my head. It does not seem to like getCustomFieldValue for product-component. This was in the JIRA logs:
/secure/CreateIssueDetails.jspa [jmwe.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [product-component]
groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [product-component]
Here is the code I put in:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType import com.atlassian.jira.issue.customfields.option.Option import com.atlassian.jira.issue.fields.CustomField Issue issue = ComponentAccessor.getIssueManager().getIssueObject("SA-991"); CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("project-component"); Map<String, Option> params = (HashMap<String,Option>) issue.getCustomFieldValue(customField) if (params != null) { Option parent = params.get(CascadingSelectCFType.PARENT_KEY) Option child = params.get(CascadingSelectCFType.CHILD_KEY) }
I am running JIRA 6.4.7, hopefully I don't need to upgrade to 7 as that is scheduled for the summer of this year. Should be running the latest of MISC Workflow extensions (4.0.4) and JIRA Misc Custom Fields (1.6.4)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I dint try to use the Misc workflow extensions. I mostly use Script Runner from Adaptavist and use Script Postfunction as a postfunction.
I see in documentation the actual issue on which you put the post function is available by name "issueObject". Issue is more a generic value. So if you use issue, you should use something like issue.get("product-component")
And yes you dont need to upgrade to 7 for it to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried Script Runner use a script as a post function and get the identical error. I will try to do this on the production server on a dummy project just to make sure it is not the sandbox. On the production I get this error. And it only has script runner installed....
/secure/CreateIssueDetails.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:1095)
at com.atlassian.jira.issue.Issue$getCustomFieldValue$4.call(Unknown Source)
at Script29.run(Script29.groovy:8)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like the only answer I can get to work is this https://innovalog.atlassian.net/browse/JMWE-178 which allows me to create a Calculated Text field which will display the parent, and see that instead of a post function copy. That answer is less than ideal as then the cascading select and the components can be out of sync if someone edits the component, but it is the best I can get working. Thanks @Vijay Khacharia for all your help, but I get errors with all the recommended groovy scripts. (possibly as I am still using the last free version of script runner)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.