Hello guys! I hope someone could help me with my issue.
I'm using Insight Postfunction Groovy script for adding comment on insight objects in Custom Field (Insight Object/s). However, since I have more than one objects in one custom field, it only adds comment to the first . Is there any chance to add comment to all Objects in Custom Field?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.riadalabs.jira.plugins.insight.services.model.CommentBean;
/* Custom field for the organisation */
CustomField insightObjectCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10200);
if (insightObjectCF == null || insightObjectCF.getValue(issue) == null) {
return false;
}
/* Get Insight Object Facade from plugin accessor */
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
/* Make sure required in this example */
def objectBean = insightObjectCF.getValue(issue)[0];
CommentBean commentBean = new CommentBean();
commentBean.setComment("This is a comment");
commentBean.setRole(0); // Public
commentBean.setAuthor(currentUser.getKey());
commentBean.setObjectId(objectBean.getId());
objectFacade.storeCommentBean(commentBean);
/* We are done! */
return true;
Reply from 2023, as I found your code useful, will attach the reply.
You need to edit
def objectBean = insightObjectCF.getValue(issue)[0];
remove the [] which specify which object you are looking for. Instead of that, you have to receive the Array of Objects and the itterate over the Array like for object in objects etc.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.