Forums

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

Help needed with Custom field and Issue Security level

Vin May 9, 2018

Hello experts,

I have multiple teams accessing same JIRA server project. I have set up Issue level security to ensure confidentiality is maintained.  I import my issues using the CSV file. I figured that there is no way to set the Issue level security in CSV file because Security level cannot be mapped while importing. This is what I tried to solve this problem.

 

I created a temporary custom field in JIRA to hold the team name. This field is populated in CSV file. Used a post script function to copy the value from custom field to "Security Level" field. Default value for "security level" is "none".

 

When I import the issues, I see that the values are copied to custom filed from CSV file. But the post function is not working. I used "Copy Value From Field to Field" post function. I tried various combinations with checkbox to experiment. But when issue is created, none is assigned to the security level. 

 

Can any of you help me!!

2 answers

0 votes
Vin May 18, 2018

Resolved this. What a relief!! :) 

Used a post function "Script Post-function" for the transition. Selected "Set issue security level depending on provided condition" script from the available list. 

 

Further from the available examples, selected "Has string custom field value equal to" example and replaced my custom filed name and the custom filed value for the condition parameter. 

Selected the appropriate security level from the drop down list. 

Now I can set the team name in my CSV file. Automatically the issue level security will be set. 

 

yes, I have different teams, I will have to add all of the conditions in a file and then pass the file to the script (I am working on this now).

Vin May 18, 2018

Hi back again,

 

I am able to achieve using above method. But in my case, I have 30 odd teams. 

I am able to check the conditions for several teams in script, but am not able to set the value as I do not have an API with which I can set. 

issue.setSecurityLevel, issue.setSecurityLevelId does not seem correct on latest version of JIRA server. We use 7.3 version.

0 votes
Nic Brough -Adaptavist-
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.
May 9, 2018

Custom fields contain custom field data (I don't know if you used a string based custom field, or a select list, which will contain options).  The security level field contains a security level.

Copying a value won't work, as they're different things.  You will need to do some scripting - something to read the string/option, find the equivalent security level and set that.

Vin May 10, 2018

Hi Nic,

 

Thanks for the comment. I have used a string based custom field in JIRA.  CSV file is generated from excel which has exact drop down names as what is configured for Security level. 

 

My CSV has TeamA as value for this custom field. 

After I import, I see this value is copied correctly. 

 

I can manually go and select TeamA for security level. But I want to copy the value from this custom field. Cant this be done using post function?

Nic Brough -Adaptavist-
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.
May 10, 2018

I am afraid you have missed the point of my answer.  A security level is not a string.  That is why it fails.

Your post-function needs to read the string, find the equivalent security level and set that.

Vin May 14, 2018

Hi Nic,

 

 I am new to groovy script. But with the help of other questions, this is what I did.

Custom field value is 13908 and custom security values are 10902 for TeamA. Default team has a custom security field value as 10702.


def Team = getCustomFieldValue(13908) //Team custom field

if(Team == "TeamA") //Check if the custom field has the field name updated
{
issue.setSecurityLevelId(10902)
}
else //Default team that should work on issues
{
issue.setSecurityLevelId(10702)
}

I have a basic compilation error. I searched further, but the results talk about Behaviors. 

Other JIRA projects (under same JIRA server) has scripts running. They use this variable in their script. 

The variable [issue] is undeclared.

 I tried to import some of the standard libraries (which was not done in other scripts). It did not help as well.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
Vin May 14, 2018

[retyping the reply again]

 

Hi Nic,

 

I am new to Groovy script. With the details from this forum, this is what I did.

import com.atlassian.jira.issue.Issue

def Team= getCustomFieldValue(13908) //custom field- Team

if(Team== "TeamA")
{
issue.setSecurityLevelId(10902)
}
else //Default Team to work on issues
{
issue.setSecurityLevelId(10702)
}

But I have a basic compilation error

The variable [issue] is undeclared.

I have tried to import some of the other standard libraries. but this did not help as well.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

When I checked further about this on forum, the answers were talking about behaviors. Under same JIRA server, there are other projects who use this variable in their scripts. 

Nic Brough -Adaptavist-
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.
May 14, 2018

The object "issue" will only be available in certain places.

Where is your script running?

Vin May 14, 2018

This script is run in the script console. Before publishing the script, I want to test the script.

 

Add-Ons->Script Runner-> Script Console.

 

As mentioned earlier, there are several projects under same JIRA server. But the field IDs that are used are specific to my JIRA project and hence I assume that script will be applicable only for my project.

Vin May 17, 2018

Hi Nic, 

 

Do you have any suggestions further? 

Nic Brough -Adaptavist-
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.
May 17, 2018

Ok, when you run in the console, there's no context - it's something you're just running in Jira.

When you run in a post-function or validator etc, you have the context of it running as things happen in the issue, so you have an issue object available to work with.

For console testing, I'd pick an issue and (temporarily) add something like

def issue = issueManager.getIssueByKey("TST-123")

(That call is off the top of my head, I'm not sure there's a getIssueByKey function, but have a look at the issueManager - there will be something that says "get an issue to work with")

Vin May 18, 2018

Hi Nic,

Even when i used a particular issue to test the script, i had the error continued. So I dropped the idea of using the console and updated the script in workflow (post function).

When i updated the same in the workflow, JIRA did throw "setSecurityLevelId" method not found. 

When i checked the JIRA API documentation, I did not see setSecurityLevelId method.

 

https://docs.atlassian.com/DAC/javadoc/jira/reference/com/atlassian/jira/issue/Issue.html

Is there any other way to set the value to security level. 

Suggest an answer

Log in or Sign up to answer