Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

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

Create Jira issue in specific Jira project based on selected Insight assets

Mohamed Ramadan October 2, 2024

Hi,

I've in Jira project insight custom field, including more than 100 assets/values.

also I've 100 Jira projects, each project have same name of one of the existing Jira projects.

EX: Insight field having values (A,B,C,....) , existing Jira projects (A,B,C,...).

 So what I need when the user select value "A" from the insight field then the post function in a specific status outcome to create issue "type = task" in the same project "A".

And so on, when the user select from insight field value "B" then post function creates 

 

issue "type = task" in the same project "B".

 

how can do this?

 

 

Regards,

1 answer

1 accepted

0 votes
Answer accepted
Sergei Troshin
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 3, 2024

Hi @Mohamed Ramadan

Do you have any plguin that allows scripting, for example Scriptrunner?

I can write an example code and you will need to put the IDs of your objects there.

Mohamed Ramadan October 5, 2024

Hi @Sergei Troshin ,

 

Yes I've script runner.

 

Thank you

Sergei Troshin
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 6, 2024

Hi @Mohamed Ramadan

Here we are! :)

import com.atlassian.jira.issue.Issue
import com.riadalabs.jira.plugins.insight.services.model.InsightObject

Issue issue = issue //Issues.getByKey("VK-17")
ArrayList<InsightObject> projectFieldValue = issue.getCustomFieldValue(10121) as ArrayList<InsightObject>
String projectKey = projectFieldValue?.first()?.getString("Project key")

return Issues.create(projectKey, "Task") {
    setSummary(issue.getSummary())
    setDescription(issue.getDescription())

}

Paste your customfield_id value instead of my "10121" and put your attribute name storing project key instead of my "Project key". Let me know if you occure some problems or accept answer if not.

 

Tips:

You can replace line

Issue issue = issue //Issues.getByKey("VK-17")

with

Issue issueIssues.getByKey("%YOUR_SOURCE_ISSUE_KEY%")

and test this code from Script Console

Mohamed Ramadan October 13, 2024

Thanks for your effort.

 

I've 5 child issues linked to main issue, these childs have "start dev date" and "End dev date" CF.

 

I need when the main issue moved to specific status then to copy the minimum "start dev date" and the maximum "End dev date" from these childs.

 

How can I do this?

 

 

Regards,

Sergei Troshin
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 13, 2024

Hi @Mohamed Ramadan

Does my solution work? Please accept it if it does.

Regarding your second question, have you linked your child issues using the Sub-task or Link function?

Mohamed Ramadan October 13, 2024

Hi @Sergey Troshin,

 

Child issues using Portfolio for Jira add-on that become "Advanced Road map for Jira" using the hierarchy configuration.

 

Regards,

Sergei Troshin
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 16, 2024 edited

Hi @Mohamed Ramadan 

Try this:

 

 

import java.sql.Timestamp
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink

final Long START_DEV_DATE_CF_ID = 11200 // start dev date
final Long END_DEV_DATE_CF_ID   = 12400 // end dev date

//def issue = Issues.getByKey("VK-29")

ArrayList<IssueLink> outWardLinks = issue.getAllOutwardLinks() as ArrayList<IssueLink>

if (outWardLinks && outWardLinks.size()) {
    ArrayList<Long> startDevDatesList = new ArrayList<>()
    ArrayList<Long> endDevDatesList = new ArrayList<>()

    for (IssueLink outWardLink : outWardLinks) {
        Issue destinationIssue = outWardLink.getDestinationObject()
        Timestamp stardDevDate = destinationIssue.getCustomFieldValue(START_DEV_DATE_CF_ID) as Timestamp
        if (stardDevDate) {
            startDevDatesList.add(stardDevDate.getTime())
        }

        Timestamp endDevDate = destinationIssue.getCustomFieldValue(END_DEV_DATE_CF_ID) as Timestamp
        if (endDevDate) {
            endDevDatesList.add(endDevDate.getTime())
        }
    }

    if (startDevDatesList && endDevDatesList) {
        Timestamp minStartDevDate = new Timestamp(startDevDatesList.min())
        Timestamp maxEndDevDate = new Timestamp(endDevDatesList.max())

        issue.update {
            setCustomFieldValue(START_DEV_DATE_CF_ID, minStartDevDate)
            setCustomFieldValue(END_DEV_DATE_CF_ID, maxEndDevDate)
        }
    }
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Upcoming Jira Service Management Events