Copy the "mentioned-in" link (link to confluence page) from the parent-issue to the new sub-task.

Madhusudhan Matrubai June 11, 2018

Hi There, I have a requirement to copy the "mentioned-in" link (link to confluence page) from the parent-issue to the new sub-task.

1. I have tried using scriptrunner approach to create sub-task and copy "All" the fields and unfortunately it does not copy "mentioned-in" link. I have also tried to exclusively specify the field values and included "issue links" and that did not help either.

2. Using JSU, tried to copy the "Issue Links" but the option is not available.

 

Do anyone have tips or tricks to get this working?

2 answers

1 accepted

3 votes
Answer accepted
Joanna Choules
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.
June 13, 2018

Hi Madhusudhan,

A Jira issue will only include a "mentioned in" link to a Confluence page if the issue is referenced in the page with a Jira Issue Macro - see the first sub-heading here: https://www.atlassian.com/blog/confluence/link-jira-issues-to-confluence-pages-automatically. This is computed automatically by the application: you cannot add it yourself, either in the UI or through the Jira API. The only way you could make a sub-task have the same "mentioned in" link as its parent would be if you changed the content of the relevant Confluence page so that it mentioned the subtask as well as the parent.

J

Madhusudhan Matrubai June 13, 2018

Hey @Joanna Choules,

Thanks for your response, that was helpful and makes sense. But then can we instead copy this as "Wiki link" ? From Parent to Sub-Task ?

The need here being that wiki page is a release notes for the Release Jira and we have sub-task releases for different regions and it would be nice to have the release notes reference on those as well.

Hope that helps give you the background.

 

Thanks,
Madhu

Joanna Choules
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.
June 18, 2018

Hi Madhu,

If 'Wiki link' is a regular custom field then yes, you should be able to copy it from parent to subtask in the same way you would for any custom field. Or do you mean something else by 'wiki link'?

J

Madhusudhan Matrubai June 18, 2018

Hey @Joanna Choules

Sorry "wiki link" I mean when we try to associate any Jira with a confluence page, it's saved as "wiki link" . You can try on any of your Jira's by trying to link to a confluence page and it will be saved as "wiki link"

Let me know if that answers your enquiry.

Thanks,
Madhu

Joanna Choules
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.
June 19, 2018

Hi Madhu,

Ok, yes, I see what you're referring to now. I've not tested the following code but it should copy every remote Confluence link from one issue to another:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor

Issue issue
Issue parentIssue

def rilm = ComponentAccessor.getComponent(RemoteIssueLinkManager)
def u = ComponentAccessor.jiraAuthenticationContext.loggedInUser

rilm.getRemoteIssueLinksForIssue(parentIssue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {
rilm.createRemoteIssueLink(
new RemoteIssueLinkBuilder(it)
.issueId(issue.id)
.build(),
u
)
}

Of course you'll need to set values for issue and parentIssue as appropriate.

Madhusudhan Matrubai June 19, 2018

Thanks Jake for the code but I'm still not lucky yet. I have modified the code as below 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.component.ComponentAccessor

//Issue issue
//Issue parentIssue
def parentIssue = issue.parentObject
assert (parentIssue)

def rilm = ComponentAccessor.getComponent(RemoteIssueLinkManager)
//def u = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def u = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

rilm.getRemoteIssueLinksForIssue(parentIssue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {
rilm.createRemoteIssueLink(
new RemoteIssueLinkBuilder(it)
.issueId(issue.id)
.build(),
u
)
}

but then I end up getting the error as mentioned below.

2018-06-19 09:37:25,920 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
com.atlassian.jira.exception.CreateException: Missing mandatory field: issueId
 at com.atlassian.jira.issue.link.DefaultRemoteIssueLinkManager.validateMandatoryFieldsForCreate(DefaultRemoteIssueLinkManager.java:249)
 at com.atlassian.jira.issue.link.DefaultRemoteIssueLinkManager.createRemoteIssueLink(DefaultRemoteIssueLinkManager.java:76)
 at com.atlassian.jira.issue.link.RemoteIssueLinkManager$createRemoteIssueLink$1.call(Unknown Source)
 at Script210$_run_closure2.doCall(Script210.groovy:17)
 at Script210.run(Script210.groovy:13)
Joanna Choules
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.
June 19, 2018

Hi Madhu,

Can you check whether issue.id is null? Depending on the context in which you're using this code, the new issue might not have been assigned an ID yet by the time that the code runs.

J

Madhusudhan Matrubai June 19, 2018

Hey Jake,

I did have this in my post function after the ticket creation and I can see issue id exists.

2018-06-19 12:08:21,687 WARN [workflow.ScriptWorkflowFunction]: Issue Id:
2018-06-19 12:08:21,687 WARN [workflow.ScriptWorkflowFunction]: 410720
2018-06-19 12:08:21,720 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-06-19 12:08:21,720 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: DUMMY-237, actionId: 1, file: <inline script>
com.atlassian.jira.exception.DataAccessException: org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:RemoteIssueLink][summary,null][statusiconurl,null][statuscategorycolorname,null][issueid,410720][statusdescription,null][globalid,appId=53cada5f-ec16-3fb0-b3b6-7df9a2d20973&pageId=198939698][statusname,null][statusiconlink,null][title,Page][url,https://wiki/pages/viewpage.action?pageId=198939698][statuscategorykey,null][applicationname,Confluence][statusicontitle,null][iconurl,null][id,37531][relationship,mentioned in][icontitle,null][applicationtype,com.atlassian.confluence][resolved,null] (SQL Exception while executing the following:INSERT INTO dbo.remotelink (ID, ISSUEID, GLOBALID, TITLE, SUMMARY, URL, ICONURL, ICONTITLE, RELATIONSHIP, RESOLVED, STATUSNAME, STATUSDESCRIPTION, STATUSICONURL, STATUSICONTITLE, STATUSICONLINK, STATUSCATEGORYKEY, STATUSCATEGORYCOLORNAME, APPLICATIONTYPE, APPLICATIONNAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (Violation of PRIMARY KEY constraint 'PK_remotelink'. Cannot insert duplicate key in object 'dbo.remotelink'. The duplicate key value is (37531).))
 at com.atlassian.jira.ofbiz.DefaultOfBizDelegator.createValue(DefaultOfBizDelegator.java:299)
 at com.atlassian.jira.ofbiz.WrappingOfBizDelegator.createValue(WrappingOfBizDelegator.java:172)
 at com.atlassian.jira.entity.EntityEngineImpl.createValue(EntityEngineImpl.java:29)
 at com.atlassian.jira.issue.link.RemoteIssueLinkStoreImpl.createRemoteIssueLink(RemoteIssueLinkStoreImpl.java:56)
 at com.atlassian.jira.issue.link.DefaultRemoteIssueLinkManager.createRemoteIssueLink(DefaultRemoteIssueLinkManager.java:87)
 at com.atlassian.jira.issue.link.RemoteIssueLinkManager$createRemoteIssueLink$1.call(Unknown Source)
 at Script250$_run_closure2.doCall(Script250.groovy:20)
 at Script250.run(Script250.groovy:16)
Caused by: org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:RemoteIssueLink][summary,null][statusiconurl,null][statuscategorycolorname,null][issueid,410720][statusdescription,null][globalid,appId=53cada5f-ec16-3fb0-b3b6-7df9a2d20973&pageId=198939698][statusname,null][statusiconlink,null][title,Page][url,https://wiki/pages/viewpage.action?pageId=198939698][statuscategorykey,null][applicationname,Confluence][statusicontitle,null][iconurl,null][id,37531][relationship,mentioned in][icontitle,null][applicationtype,com.atlassian.confluence][resolved,null] (SQL Exception while executing the following:INSERT INTO dbo.remotelink (ID, ISSUEID, GLOBALID, TITLE, SUMMARY, URL, ICONURL, ICONTITLE, RELATIONSHIP, RESOLVED, STATUSNAME, STATUSDESCRIPTION, STATUSICONURL, STATUSICONTITLE, STATUSICONLINK, STATUSCATEGORYKEY, STATUSCATEGORYCOLORNAME, APPLICATIONTYPE, APPLICATIONNAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (Violation of PRIMARY KEY constraint 'PK_remotelink'. Cannot insert duplicate key in object 'dbo.remotelink'. The duplicate key value is (37531).))
 at org.ofbiz.core.entity.GenericDAO.singleInsert(GenericDAO.java:206)
 at org.ofbiz.core.entity.GenericDAO.insert(GenericDAO.java:171)
 at org.ofbiz.core.entity.GenericHelperDAO.create(GenericHelperDAO.java:89)
 at org.ofbiz.core.entity.GenericDelegator.create(GenericDelegator.java:562)
 at org.ofbiz.core.entity.GenericDelegator.create(GenericDelegator.java:548)
 at org.ofbiz.core.entity.GenericValue.create(GenericValue.java:114)
 at com.atlassian.jira.ofbiz.DefaultOfBizDelegator.createValue(DefaultOfBizDelegator.java:296)
 ... 7 more
Caused by: org.ofbiz.core.entity.GenericDataSourceException: SQL Exception while executing the following:INSERT INTO dbo.remotelink (ID, ISSUEID, GLOBALID, TITLE, SUMMARY, URL, ICONURL, ICONTITLE, RELATIONSHIP, RESOLVED, STATUSNAME, STATUSDESCRIPTION, STATUSICONURL, STATUSICONTITLE, STATUSICONLINK, STATUSCATEGORYKEY, STATUSCATEGORYCOLORNAME, APPLICATIONTYPE, APPLICATIONNAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) (Violation of PRIMARY KEY constraint 'PK_remotelink'. Cannot insert duplicate key in object 'dbo.remotelink'. The duplicate key value is (37531).)
 at org.ofbiz.core.entity.jdbc.SQLProcessor.executeUpdate(SQLProcessor.java:570)
 at org.ofbiz.core.entity.GenericDAO.singleInsert(GenericDAO.java:198)
 ... 13 more
Caused by: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK_remotelink'. Cannot insert duplicate key in object 'dbo.remotelink'. The duplicate key value is (37531).
 at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
 at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988)
 at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421)
 at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671)
 at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:613)
 at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:572)
 at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:727)
 at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:98)
 at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:98)
 at org.ofbiz.core.entity.jdbc.SQLProcessor.executeUpdate(SQLProcessor.java:562)
 ... 14 more
Joanna Choules
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.
June 20, 2018

Hi Madhu,

Is this new error occurring instead of the previous one, or are you still seeing both? If it's just the new error then I think you should be able to solve it by replacing this code:

new RemoteIssueLinkBuilder(it)
.issueId(issue.id)
.build()

with this:

new RemoteIssueLinkBuilder(it)
.id(null)
.issueId(issue.id)
.build()

J

Like Marvin Spiegel likes this
Madhusudhan Matrubai June 20, 2018

Awesome, it worked this time. Thank you Sir, appreciate your time and efforts to resolve this.

Thank you,

Madhu

1 vote
Omprakash Thamsetty
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.
October 23, 2020

@Joanna Choules @Madhusudhan Matrubai I used this script to copy the confluence link from parent to Linked issues. It works like a charm. But I would like to validate before creating the link. If the confluence link already exists on the Linked issue then ignore creating the link. 

 

How can we  validate it?

 

Thanks,

Om

Suggest an answer

Log in or Sign up to answer