Forums

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

Questions not appearing after a Rebuild from scratch of the Index. Do I need to restore?

Quinn Cervantes-Prevo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 29, 2018

We had issues where only some of the questions weren't appearing in some of our spaces. We attempted to complete a UI driven rebuild of the content index, and that failed due to an OOM received. It was decided to adjust our heap and rebuild from scratch our content index. Now we can only see ~15 questions overall. We see there are questions that have been asked, and the only way to view those old ones, is if there is a direct link reference elsewhere in a page. 

Should we restore our index directory or question directory at this point? Is there another index we should complete? 

 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Tansu Akdeniz
Community Champion
June 23, 2021

Hi @Chris Annal 

Custom script is needed for it.

Please check this code for link creation from customfield which may help you. If you need to validate Related Tech Review in transition then you need to write validation script.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

Issue sourceIssue = ComponentAccessor.getIssueManager().getIssueObject("ABC-XXX");

CustomField techRevCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11111");
String techRevVal = sourceIssue.getCustomFieldValue(techRevCF);

Issue destIssue = ComponentAccessor.getIssueManager().getIssueObject(techRevVal);

ComponentAccessor.getIssueLinkManager().createIssueLink(sourceIssue.getId(),destIssue.getId(),10001L,0L,currentUser)

 Java api: https://docs.atlassian.com/software/jira/docs/api/latest/

Chris Annal
Contributor
June 23, 2021

Thanks, Tansu!! This is very helpful...but I have a question. In your example, it looks like you are hard-coding the current issue number (

getIssueObject("ABC-XXX"); 

Is there a way to get that issue number as the current issue?

Tansu Akdeniz
Community Champion
June 23, 2021

You are welcome.

In script console, you can test with the code above via manuel issue key.

But in workflow, please use this one.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

CustomField techRevCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11111");
String techRevVal = issue.getCustomFieldValue(techRevCF);

Issue destIssue = ComponentAccessor.getIssueManager().getIssueObject(techRevVal);

ComponentAccessor.getIssueLinkManager().createIssueLink(issue.getId(),destIssue.getId(),10001L,0L,currentUser)

ps: I removed this line:

Issue issue = ComponentAccessor.getIssueManager().getIssueObject("ABC-XXX");

System will get "issue" as a current issue object automatically. So, you don't have to define it.

Like Chris Annal likes this
Chris Annal
Contributor
June 24, 2021

Thanks again, Tansu!!

I ran into a minor glitch in that the "current issue" has to exist (issue.getId()), so this post function might be placed after the initial "Create" step in a workflow. I also named the specific Link Type (issueLinkName) that I wanted to use, and so far, this seems to work. I actually put the custom field in a workflow screen that pops up during the transition, so the user is presented with it and can enter the desired issue number to link to. Another option might be to put it on an "Edit" screen, but not the "Create" screen. Anyway, this is what seems to work for me so far. Thanks again for all your help!!!

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;

// "customfield_xxxxx" is the custom field used for linking, replace with actual custom field ID
CustomField techRevCF= ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_xxxxx");
String techRevVal = issue.getCustomFieldValue(techRevCF);
Issue destIssue = ComponentAccessor.getIssueManager().getIssueObject(techRevVal);
final String destinationIssueKey = techRevVal

// the name of the issue link
final String issueLinkName = "Related_ETR"

// the sequence of the link
final Long sequence = 1L

// get current user to perform the linking
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.issueManager
def destinationIssue = issueManager.getIssueByCurrentKey(destinationIssueKey)
assert destinationIssue: "ETR issue does not exist"
def availableIssueLinkTypes = issueLinkTypeManager.issueLinkTypes
def linkType = availableIssueLinkTypes.findByName(issueLinkName)
assert linkType : "Could not find link type with name $issueLinkName. Available issue link types are ${availableIssueLinkTypes*.name.join(", ")}"
ComponentAccessor.issueLinkManager.createIssueLink(issue.getId(),destinationIssue.id, linkType.id, sequence, currentUser)
Tansu Akdeniz
Community Champion
June 25, 2021

Glad to hear that it worked !! If you could accept the answer, it may help other people to find the answer easier.

Chris Annal
Contributor
June 25, 2021

Thanks again for all your help. I accepted the answer (and liked it, too). 

:)

For bonus points, someone may want to work on handling the error that is displayed if the target issue of the link is "null" (bad data entry). You touched on the need for validation, so that's what I'm working on now - but the script works fine when the target issue is an existing issue key value. 

:)

Tansu Akdeniz
Community Champion
June 25, 2021

Validator is easier than post-function. Sample one:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.opensymphony.workflow.InvalidInputException

CustomField techRevCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11111");
String techRevVal = transientVars["issue"].getCustomFieldValue(techRevCF);

if(ComponentAccessor.getIssueManager().getIssueObject(techRevVal) == null){
invalidInputException = new InvalidInputException("Issue not found in Jira.")
}

TAGS
AUG Leaders

Atlassian Community Events