You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi Community,
I am trying to fill in Insight object(s) custom field, which is configured as multiple.
Here is the code:
if (members != null)
{
for (item in members)
{
def userInsightField = customFieldManager.getCustomFieldObject("customfield_11525") // TSO members (Insight)
Class iqlFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade")
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(iqlFacadeClass)
def member = iqlFacade.findObjectsByIQLAndSchema(3,"\"User Jira Key\" = " + item.key) // Schema 3 = Customer Directory
if (issue.getCustomFieldValue(userInsightField) == null)
{userInsightField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(userInsightField), member), changeHolder)}
else
{userInsightField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(userInsightField), issue.getCustomFieldValue(userInsightField) + member), changeHolder)}
//return issue.getCustomFieldValue(userInsightField)
}
}
In members, there is an ArrayList of DelegatingApplicationUser
In the return section, I am getting two objects
When executed in post function, only one object is in the field.
Was search for solution for hours, but no success, please, help me out :-)
hi @Tomáš Vrabec as @Peter-Dave Sheehan suggested you have to use issue.setCustomFieldValue method otherwise it is still NULL when the code is in second, third... loop. It could be
def emails = ['alex.hrabal@metrostavfake.cz', 'frantisek.silny@cetinfake.cz']
for(def item in emails){
def member = iqlFacade.findObjectsByIQLAndSchema(1,"\"Email\" = " + item)
if (issue.getCustomFieldValue(userInsightField) == null) {
issue.setCustomFieldValue(userInsightField, member) // you have to invoke this, otherwise issue.getCustomFieldValue is still null
log.error("null:"+item)
userInsightField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(userInsightField), member), changeHolder)
} else {
log.error("not null:"+item)
def oldValue = issue.getCustomFieldValue(userInsightField)
def newValue = oldValue + member
issue.setCustomFieldValue(userInsightField, newValue)
userInsightField.updateValue(null, issue, new ModifiedValue(oldValue, newValue), changeHolder)
}
}
But I would try to optimize it and not to set the field with value by value but you should create collection of Insight objects and set it at once. In my case:
def emails = ['alex.hrabal@metrostavfake.cz', 'frantisek.silny@cetinfake.cz']
def insightObjects = []
for(def item in emails){
def member = iqlFacade.findObjectsByIQLAndSchema(1,"\"Email\" = " + item)
if(member){
member = member.get(0)
insightObjects.add(member)
}
}
def oldValue = issue.getCustomFieldValue(userInsightField)
def newValue = oldValue!=null ? new ArrayList(oldValue):[]
insightObjects.each{newValue.add(it)}
issue.setCustomFieldValue(userInsightField, newValue)
userInsightField.updateValue(null, issue, new ModifiedValue(oldValue, newValue), changeHolder)
Ahoj @Martin Bayer _MoroSystems_ s_r_o__
My final version looks like this:
if (members != null)
{
def userInsightField = customFieldManager.getCustomFieldObject("customfield_11525") // TSO members (Insight)
for(item in members)
{
def member = iqlFacade.findObjectsByIQLAndSchema(3,"\"User Jira Key\" = " + item.key)
if(member)
{
member = member.get(0)
insightObjects.add(member)
}
}
def oldValue = issue.getCustomFieldValue(userInsightField)
def newValue = oldValue!=null ? new ArrayList(oldValue):[]
insightObjects.each{newValue.add(it)}
issue.setCustomFieldValue(userInsightField, newValue)
userInsightField.updateValue(null, issue, new ModifiedValue(oldValue, newValue), changeHolder)
}
But yes, it does work! Thanks for the tip with oldValue and newValue, this is exactly what I was looking for! Kudos and accepted answer for you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not a fan of the customFieldObject.updateValue() method in general because I don't think it will appear in the issue history.
But in your specific case, I would guess that the value you are setting with this low-level api is being updated by the temporary issue object values (which are not updated after you update the custom field value) that the postfunction is holding in memory.
Instead, I would recommend you use the issue.setCustomFieldValue() or issueInputParameters.addCustomFieldValue() methods. Then the rest of the postfunction mechanism will take care of storing those values.
Another approach is to move your post function to the end of the post function sequence (after the store issue object function).
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.