Hello, I have a working code that extract Insight attribute data by using attribute name:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.text.SimpleDateFormat
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule ObjectFacade objectFacade
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
def f = getFieldById(getFieldChanged())
String objectKey = f.getValue()
def insightObject = objectFacade.loadObjectBean(objectKey)
int objectId = insightObject.getId()
String InsightFirstName = "First Name"
def InsightFNAttribute = objectFacade.loadObjectAttributeBean(objectId, InsightFirstName)
def InsightFNAttributeValues = InsightFNAttribute.getObjectAttributeValueBeans()
def InsightFNAttributeValue = InsightFNAttributeValues[0]
def FirstName = InsightFNAttributeValue.value
String InsightLastName = "Last Name"
def InsightLNAttribute = objectFacade.loadObjectAttributeBean(objectId, InsightLastName)
def InsightLNAttributeValues = InsightLNAttribute.getObjectAttributeValueBeans()
def InsightLNAttributeValue = InsightLNAttributeValues[0]
def LastName = InsightLNAttributeValue.value
___________________________________________________________________________
FirstName & Lastname successfully get the correct data.
How can I turn this piece of code into a working function?
I have a lot more attribute to extract and I dont want to duplicate those lines again.
I want to call a function that will extract that data for me with just 1 line of code per attribute.
Thank you in advance,
Daniel.
Hi @Daniel Ben Eliyahu , I think it is enough to implement function similar to:
def getAttributeValue(def objectFacade, def objectId, def attributeName){
def attributeBean = objectFacade.loadObjectAttributeBean(objectId, attributeName)
def attributeValues = attributeBean.getObjectAttributeValueBeans()
def attributeValue = attributeValues[0]
def attribute = attributeValue.value
return attribute
}
and call it like:
def FirstName = getAttributeValue(objectFacade, objectId, InsightFirstName)
def LastName = getAttributeValue(objectFacade, objectId, InsightLastName)
Hello Martin,
Thank you for your answer.
Why am I getting an error like this?
[Static type checking] - The variable [objectFacade] is undeclared.
@ line 38, column 25.
and line 38 is:
def attributeBean = objectFacade.loadObjectAttributeBean(objectId, attributeName)
Thanks!
Daniel.
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.
Thank you @Martin Bayer [MoroSystems, s.r.o.] !
I've applied your code and I get another error on this line:
def attributeBean = objectFacade.loadObjectAttributeBean(objectId, attributeName)
Is it something Wrong I did?
my current code is: (on ScriptRunner Behaviours)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import org.apache.log4j.Logger
import org.apache.log4j.Level
import java.text.SimpleDateFormat
@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule ObjectFacade objectFacade
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
def f = getFieldById(getFieldChanged())
//f.setHelpText("RawValues: ${f.rawValue} <br><font color=green>Value: <b>$f.value</b></font> <br>FromValue: $f.formValue ")
String objectKey = f.getValue()
def insightObject = objectFacade.loadObjectBean(objectKey)
int objectId = insightObject.getId()
def OnlyNumbers = extractInt(objectKey)
def getAttributeValue(def objectFacade, def objectId, def attributeName){
def attributeBean = objectFacade.loadObjectAttributeBean(objectId, attributeName)
def attributeValues = attributeBean.getObjectAttributeValueBeans()
def attributeValue = attributeValues[0]
def attribute = attributeValue.value
return attribute
}
def FirstName = getAttributeValue(objectFacade, objectId, InsightFirstName)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Daniel Ben Eliyahu , static code check is not so important in groovy because we are not using "types" as we use in Java.
This code should work. We need to only fix runtime errors, but you have to execute the code so we know if there are any errors.
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.