Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,741
Community Members
 
Community Events
184
Community Groups

How to set WikiPage link (remote link from Confluence) into a custom field - ScriptRunner

Hey guys, someone could help me with codes/tips/whatever pls ?

 

I'm trying to copy the Wiki Page link (Confluence link)  to a Custom Field named Wiki Page. Trying to do it with Listener.

 

I was able to retrieve the remote link, but I cannot set it into the CF. Following the script and the error as well.

import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.ListLinks")
log.setLevel(Level.DEBUG)
//-------------------------------------------------------------------------------------------------------------------------------------------
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue

def issue = event.issue as MutableIssue
def cfManager = ComponentAccessor.getCustomFieldManager();
def ilkManager = ComponentAccessor.getIssueLinkManager();
def changeHolder = new DefaultIssueChangeHolder();
def RemoteLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)
def linkBuilder = new RemoteIssueLinkBuilder()
def remoteLinks = RemoteLinkManager.getRemoteIssueLinksForIssue(issue)?.collect {"From Application ${it.applicationName}, Title ${it.title}, URL: ${it.url}"}?.join("<br>")

RemoteLinkManager.getRemoteIssueLinksForIssue(issue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {WikiPageLink ->
def cfWikiPage = cfManager.getCustomFieldObjects(issue).find {it.name == "Wiki Page"}

cfWikiPage.updateValue(null, issue, new ModifiedValue(cfWikiPage, remoteLinks),changeHolder)

// issue.setCustomFieldValue(null, issue, new ModifiedValue(WikiPageLink2, cfWikiPage),changeHolder)

log.debug("Wiki Page = " + remoteLinks)

}

 

Any help is welcome.

 

Thanks all.

 

Cassio.

Listener_WikiPage_Error.png

2 answers

1 accepted

0 votes
Answer accepted

I was able to correct the script and to set the URL link into the custom field.

 

Below are the parameters and the corrected script.

 

Script type: Custom Listener;

Events: All Issue Events;

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder


IssueEvent event = event
def issue = event.getIssue()
def cfManager = ComponentAccessor.getCustomFieldManager();
def ilkManager = ComponentAccessor.getIssueLinkManager();
def changeHolder = new DefaultIssueChangeHolder();
def RemoteLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)
def linkBuilder = new RemoteIssueLinkBuilder()
def remoteLinks = RemoteLinkManager.getRemoteIssueLinksForIssue(issue)?.collect {"${it.url}"}?.join("<br>")

RemoteLinkManager.getRemoteIssueLinksForIssue(issue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {WikiPageLink ->
def cfWikiPage = cfManager.getCustomFieldObjects().find {it.name == "Wiki Page"}
def url = remoteLinks.toString()

cfWikiPage.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfWikiPage), url),changeHolder)
}
0 votes
Alejandro Suárez
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 Leaders.
Jun 03, 2019

@Cassio Miranda What type of Custom Field are you trying to set?

@Alejandro Suárez I managed to correct my script and now it's setting the URL into the custom field. I'll post the corrected script with the parameters I set.

Thank you for your concern.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events