Creating an instight object using HAPI isn't working as expected

Ismael Jimoh January 16, 2025

When I try to create or update an Asset using the HAPI's setAttribute Add method, I noticed that it is creating the item but only sets the last attribute from the source field.

Here's a snippet of the code I am using:

createdAsset.update { 

if(riskFieldValue){

log.warn(riskFieldValue)

for(int counter=0;counter < riskFieldValue.size(); counter++){

if(counter == 0){

setAttribute('Risk'){

log.warn(riskFieldValue[0])

add(Assets.getById(riskFieldValue[0].getId()))

}

}else{

setAttribute('Risk'){

log.warn(riskFieldValue[counter])

add(Assets.getById(riskFieldValue[counter].getId()))

}

}

}

}

if(processRiskOccursFieldValue){

log.warn(potentialFailureModeFieldValue)

for(int counter=0;counter < processRiskOccursFieldValue.size(); counter++){

if(counter == 0){

setAttribute('Process where the risk occurs'){

log.warn(processRiskOccursFieldValue[0])

add(Assets.getById(processRiskOccursFieldValue[0].getId()))

}

}else{

setAttribute('Process where the risk occurs'){

log.warn(processRiskOccursFieldValue[counter])

add(Assets.getById(processRiskOccursFieldValue[counter].getId()))

}

}

}

}

}
Here's the snippet I am referring to: 

https://docs.adaptavist.com/sr4js/latest/hapi/work-with-assets-insight#updating-attributes

 

Could anyone help with reviewing and letting me know why I am running into an issue where it is not taking all the Assets from the field and directly setting them in the created/updated Asset attribute?

Thanks.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events