Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Error updating asset with script

Rait Pommer
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!
July 6, 2023

Hello,

I am currently experiencing an issue with my Jira script for updating/changing assets. Below is the code I'm using:

"
def objectType = objectTypeFacade.loadObjectTypeBean(originalObject.getObjectTypeId())
def newObjectBean = objectType.createMutableObjectBean()

newObjectBean.setId(originalObject.getId())
newObjectBean.setObjectAttributeBeans(attributes)

try {
objectFacade.storeObjectBean(newObjectBean)
} catch (Exception e) {
log.info("Error: " + e)
}
"

In one use case, although I receive an error message stating:

"com.riadalabs.jira.plugins.insight.common.exception.RuntimeInsightException: InsightRuntimeException: java.lang.NullPointerException; nested exception is: null"

but the asset is still updated correctly.
However, in another use case, when I encounter the following error:

"com.riadalabs.jira.plugins.insight.common.exception.ValidationInsightException: ValidationInsightException: Validation errors were found: rlabs-insight-attribute-1240: ErrorMessage{i18nKey='rlabs.insight.i18n.constraint.violation.unique', parameters=[uncode], additionalMessage=null};"

the asset fails to update. Using the "objectFacade.storeObjectBeanIgnoreAttributeValidation(newObjectBean)" method allows for a successful update, although it throws the same error as in the first use case.

I have been unable to find a solution for these errors, and I would greatly appreciate any assistance or insights that can be provided.

1 answer

0 votes
vahem2lu July 7, 2023

Hi community and all,

This script runs when new object is being created and checks if database already has another object with the same "Name".

If yes, then it does two things:

  • Copy some attributes from "old" (OBJ-1) to "new" object (OBJ-100) which is being created.
  • And also, if some of the other objects (for example OBJ-50, there's some filtering done, which is irrelevant) have this old OBJ-1 in their attribute values, then those objects needs to be updated with new object OBJ-100 as well.

There are two separate errors here which we would like to get help with. @PD Sheehan you have excellent knowledge in this, I would use possibility and mention you here again. :D

 

First problem - we need to store OBJ-50 with IgnoreAttributeValidation

Is there any idea or puprose why we need to store object with IgnoreAttributeValidation when saving/updating already existing object OBJ-50?

objectFacade.storeObjectBeanIgnoreAttributeValidation(newObjectBean)

=> As OBJ-1 was used in one of OBJ-50 attribute values, so this new OBJ-100 needs to be added to OBJ-50 attributes.

We have one attribute in this OBJ-50 schema which has "Unique" constraint. If we don't have unique constraint, we don't need to use IgnoreAttributeValidation. If we have, we need to use it, otherwise we are not able to save the same object. Is this kind of expected behaviour when using Groovy scripts to ignore attribute validation? Or is there something we are missing when we are saving the same object?

 

Second problem - nested exception null

Although all necessary attributes are being copied from OBJ-1 (old) to OBJ-100 (new) and OBJ-100 is saved correctly, we are getting "nested exception: null". Script itself does not return false nor it exists, all OBJ-100 is being updated correctly.

Somewhy after createMutableObjectBean this newObjectBean becomes null.

def objectAttributes = objectFacade.findObjectAttributeBeans(object.getId());

def allAttributes = objectAttributes + getAttributes(atts, fromObject.getId());

def objectTypeVirtualGuest = objectTypeFacade.loadObjectTypeBean(object.getObjectTypeId());
def newObjectBean = objectTypeVirtualGuest.createMutableObjectBean();

newObjectBean.setId(object.getId());
newObjectBean.setObjectAttributeBeans(allAttributes);

newObjectBean = objectFacade.storeObjectBean(newObjectBean);

 

Suggest an answer

Log in or Sign up to answer