Creating a Confluence page from Template Using Scriptrunner for Jira

Trent Alton Calvert July 22, 2024

Hi,

We have been using a script (copied below) in Scriptrunner for Jira Data Center 6.54.0 that displays a button on a transition screen that creates a Confluence page from a specific template and takes the user to that page directly to edit and publish. However, we are currently attempting to upgrade our Jira/Confluence and the script no longer functions due to the new requirement of the "atl_token" security requirement in Confluence. Unfortunately, it appears there is no way to call the user's Confluence atl_token from the Jira Scriptrunner side, currently it only calls the Jira atl_token.

Does anyone know if there is any modifications we can make to disable or get around this atl_token requirement? Thank you!

 

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import java.util.Calendar
import java.text.SimpleDateFormat
import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
import javax.servlet.http.HttpServletRequest
import com.atlassian.jira.security.xsrf.XsrfTokenGenerator
import com.atlassian.sal.api.auth.LoginUriProvider
import com.atlassian.sal.api.user.UserManager
import com.atlassian.sal.api.auth.Authenticator
import javax.servlet.http.HttpServletRequest
import com.atlassian.jira.web.ExecutingHttpRequest
import com.atlassian.annotations.security.XsrfProtectionExcluded

XsrfTokenGenerator xsrfTokenGenerator = ComponentAccessor.getComponent(XsrfTokenGenerator)
String atl_token = xsrfTokenGenerator.generateToken(null)

def issue = underlyingIssue
def summary = issue.getSummary()
def issueKey = issue.getKey()
def month = new Date().format('MMMM')
def year = new Date().format('YYYY')
String[] sum = summary.toString().split(":")
def shortsum = sum[0].toString().substring(0)
def durl1 = "https://XXXXXXX-XXXXXX-XXXX.XX.XXXXXX.com/pages/createpage-entervariables.action?" + "atl_token=" + atl_token + "&templateId=151453708&spaceKey=DINF&newSpaceKey=DINF&title=" + shortsum + ":" + "%20" + month + " " + year + " " + issueKey + "%20Baseline%20Change+"
def url = "https://XXXXX-XXXXXXX-XXXX.XX.XXXXXXX.com/pages/createpage-entervariables.action?" + "atl_token=" + atl_token + "&templateId=164921345&spaceKey=WIS&newSpaceKey=WIS&title=" + shortsum + ":" + "%20" + month + " " + year + " " + issueKey + "%20Baseline%20Change+"
def url2 = "%20&body=" + issueKey + " " + "&linkCreation=true&&fromPageId=63176868"
def durl2 = "%20&body=" + issueKey + " " + "&linkCreation=true&&fromPageId=151355988"
def completeURL = url + url2
def dcompleteURL = durl1 + durl2
def finalURL = """
<html>
<style>
      .button {
        background-color: #1c87c9;
        border-color: #04AA6D;
        color: white;
        padding: 20px 34px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 20px;
        margin: 4px 2px;
        cursor: pointer;
</style>
<body>
    <h5 style="color:#ff482e";><kbd>Middle Mouse Button</kbd> <br>    <small>OR</small><br><kbd>Ctrl</kbd> + <kbd>Left Click</kbd> on Button below to Open in New Tab (Otherwise you will need to redo this form)</h5>
    <a class="button" href="""+ '"' + completeURL + '"' + """>Create Confluence Page HERE</a>
   </body>
</html>"""

def dfinalURL = """
<html>
<style>
      .button {
        background-color: #1c87c9;
        border-color: #04AA6D;
        color: white;
        padding: 20px 34px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 20px;
        margin: 4px 2px;
        cursor: pointer;
</style>
<body>
    <h5 style="color:#ff482e";><kbd>Middle Mouse Button</kbd> <br>    <small>OR</small><br><kbd>Ctrl</kbd> + <kbd>Left Click</kbd> on Button below to Open in New Tab (Otherwise you will need to redo this form)</h5>
    <a class="button" href="""+ '"' + dcompleteURL + '"' + """>Create Confluence Page HERE</a>
   </body>
</html>"""

// Get Confluence Page Created field
def formField = getFieldById(getFieldChanged())
def Conf = getFieldById("customfield_13919")
// Get Baseline Change Required custom field
def base = getFieldById("customfield_13359")
String baseVal = base.getValue()
// Condition if baseline change required = yes then make Confluence Page Created required and set Help Text to URL Button
if (baseVal == "Yes") {
    formField.setHelpText(finalURL)
    if (issueKey.startsWith("DINF")) {
        formField.setHelpText(dfinalURL)
    }
    formField.setDescription("")
    Conf.setRequired(true)
} else {
    formField.clearHelpText()
    Conf.setRequired(false)
}

 

https://XXXXX-XXXXXXX-XXXX.XX.XXXXXXX.com

 

https://XXXXX-XXXXXXX-XXXX.XX.XXXXXXX.com

 

https://XXXXX-XXXXXXX-XXXX.XX.XXXXXXX.com

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Dave Rosenlund _Trundl_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 22, 2024

Hi, @Trent Alton Calvert. Welcome back 👋

First, I moved your post to App Central where it should be AND I added to add'l tags to (hopefully) draw the right eyeballs.

That said, while you might get an answer here from a fellow community member who has the requisite ScriptRunner expertise, you will likely find a faster resolution by opening a ticket with the ScriptRunner support team at Adaptavist.

Best of luck,

-dave

1 vote
Abi Brown- Kolekti
Atlassian Partner
July 23, 2024

Hi - have you logged a ticket with the Scriprunner support team? @Nic Brough -Adaptavist-  might be able to advise better than me!

Thanks

Abi 

Trent Alton Calvert July 23, 2024

Hey Abi, I did create a support request with Adaptavist, they were able to confirm that there was no way to call the Confluence user token from the Jira end. I am currently searching for a way to get around the security requirement or possibly accomplish the same functionality using an API call instead.

0 votes
Trent Alton Calvert July 23, 2024

Issue no longer relevant, we have decided to go in a different direction.

TAGS
AUG Leaders

Atlassian Community Events