Forums

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

I am trying to create a new Attachment for a Confluence page but have been unsuccessful

Matt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 13, 2020

Using the Java API in ScriptRunner/groovy I am trying to retrieve all attachments for a page and then create a new one if it currently does not exists.

Everything is working so far, except the creation of the new attachment.  Clearly, I'm missing something and community insight would be super helpful! I'm fairly new to Java/ScriptRunner/Groovy programming.
 
Code:

Attachment newFile = new Attachment("filename.csv", "text/csv", 6014, "new file");


Per: https://docs.atlassian.com/atlassian-confluence/6.0.3/com/atlassian/confluence/pages/Attachment.html, that should be all that is needed to construct a new Attachment object. 

Once the attachment is created I would use AttachmentManager to save the file to the page with content from InputStream/ByteArray.

Does the file/content actually need to exist on the server somewhere before I can create the attachment and save to the page?

However, I receive the following errors in the log. <snippet>


org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:873) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:710) at jdk.internal.reflect.GeneratedMethodAccessor80.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205) at com.sun.proxy.$Proxy75.commit(Unknown Source)

 

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Jeroen Poismans
Community Champion
June 27, 2022

Hello,

Few questions:

  • Is the "Spinnaker Pipeline" field visible on the Create screen?
  • If so, should the content of this field change on the Create screen when selection is made in "Affected Business Service"?

==> If answer here is Yes, then you would need a Behaviour (script).

==> If answer is No, you won't need a script if you have the JSU or JMWE app (you could use postfunction).

==> Alternatively you could use an Automation that on Create has a condition JQL where "Affected Business Service" has the trigger value and as action set your "Spinnaker Pipeline" field. This however would require the Automation for Jira app (since you are on Server).

==> If all above is not applicable, you could use a script postfunction setting the value.

Can you elaborate on your case?

 

Kind regards,

Jeroen

TAGS
AUG Leaders

Atlassian Community Events