Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

GroovyScript: Get User located in Custom Field within an issue.

N H
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 26, 2020

Hi Everyone!

     In my organization, our Jira setup has a customField_12000 which is pointed to an object labeled "Affected Objects", there can be multiple Affected Objects", Within these objects is a Contact(s) field with multiple users inside. Does anyone know an easy way to fill this value?

Taking a step back, the goal is really to target an "Affected Object" by itself and not specifically from a linked issue, then to show who is the primary contact for that object through a rest call if possible.

It seems alot of examples help me pull the Affected Object itself but not the contact within?

I messed with the GroovyScript to see if I could get it to load anything and I was able to successfully reflect the name of the affectedobject within the field but not the contact located within that specific object.

Thanks for any Pointers!!

[My failed attempts]

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
//ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12000); = "Affected Object(s)"
def value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12000)); // Change ID to the correct one

CustomField myCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12000)
def objectBean = myCF.getValue(issue)[0]

/* If an insight custom field has an object called "Microsoft" it will fail */
if (value != null && "Microsoft".equals(value[0].getName())) {
return "This is not a valid vendor!";
}
//return value[0].getAt(0).name
return objectFacade.loadObjectAttributeBean(value[0].getId(), 12000).getObjectAttributeValueBeans()[0].getValue()
return value[0].toString()
return value[0].getId()
return value[0].getLabel()
return value[0].getClass()
return value[0].getName()

 

The code above helps return some minor details of the affect object selected at index [0] but what am I missing to get the underlaying attribute?

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
N H
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 26, 2020

2020-03-26_1314.png

TAGS
AUG Leaders

Atlassian Community Events