You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.
View groupJoin the community to find out what other Atlassian users are discussing, debating and creating.
I've been making some customization in our environment that involves object creation automatically from a jira post function.
I'm using groovy to create the new object.
But I'm getting a unique constraint violation error on an attribute that I know to have a different value than any that exist.
As a test scenario, I created a brand new object type in my schema (typeId=50) with only the default attributes. I made the "name" attribute unique.
Then I wrote this simplified script to create a new value. I run this from the console:
import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
def objectTypeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeFacade)
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectTypeAttributeFacade)
def typeId = 50
def newObjectName = 'test3'
def objectType = objectTypeFacade.loadObjectType(typeId)
def objectTypeAttributes = objectTypeAttributeFacade.findObjectTypeAttributeBeans(objectType.id)
def newObject = objectType.createMutableObjectBean()
def nameOTAB = objectTypeAttributes.find{it.name=='Name'}
def nameOAB = newObject.createObjectAttributeBean( nameOTAB)
def nameOAVB = nameOAB.createObjectAttributeValueBean()
nameOAVB.setValue(nameOTAB, newObjectName)
nameOAB.setObjectAttributeValueBeans([nameOAVB])
newObject.setObjectAttributeBeans([nameOAB])
objectFacade.validateObjectBean(newObject)
log.info "Validation passed"
def object = objectFacade.storeObjectBean(newObject)
This fails on the storeObjectBean() method even when I know for sure that newObjectName 'test3' does not exist.
As proof, if an object with that Name exists, then the script fails on the validateObjectBean() method.
If I remove the Unique flag from the attribute, then the script works fine (of course whether or not the name already exists, potentially creating duplicates).
Am I doing something wrong in how I'm building up my mutableObjectBean?
Any examples out there of how to create a new object that has a unique attribute?
Well, nevermind ... I think I found my issue.
If I remove my line to validate the object then the store object works correctly. So, somehow the validateObjectBean must be creating a cached version of the object that the storeObjectBean trips over.
We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan. &nb...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.