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

Restrict Attachment Type

Hi
I want restrict attachment type in creating issue(when creating issue must be attach ONLY excel File in "creat issue screen").I writed this script, but there are error in it.
How can I fix the problem?
Can this code be a solution??

attachmentManager.getAttachments(issue).each
{(it.getfilename.endsWith(".xlsx"))}

Thanks

Marzi

 

3 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Daniel Yelamos [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.
Jan 11, 2018

Okay I just got a notification from this and thought I would step in to get some concepts out of the way.

If I'm not mistaken, at the create stage, the issue is not yet created.a

If the issue is not created, you cannot check for attachments.

This is quite a limitation that I've seen a few clients run into.

There are a few workarounds:

1. Inject a custom Javascript validator into the screen that does this for you. Which is hard in my opinion.

2. Create an intermediate stage in your workflow as follows.

If your workflow works like this ->A->B->C for example. A is your creation stage.

If you want to make sure that it only has attachments that end with the proper excel format. Instead of adding the validator in the first arrow(that symbolises the create stage) add the validator to the second arrow, that allows people to work on it. So if people want to start working on an issue, they need to make sure it has a proper attachment.

Is this clear? May I help you further?

Cheers!

Dyelamos

Hello thanks for the answer.

My requirement is like 

I will be able to have only PDF file in the attachment from the creation stage .

While creating a issue you can only attach PDF file .

Daniel Yelamos [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.
Jan 11, 2018

If you read my answer. This is impossible while using a validator. It will simply not work, because the issue isn't created until the "onCreate" transition is finished and committed to the database.

You will need to inject some short of JS script via Script Fragments in order to make this work. This is not simple at all.

Cheers!

DYelamos

Simple scripted validator

Hey does ur code worked out..I need it for my project where I need only PDF files so

Like Polina Semykina likes this
0 votes
Alexey Matveev
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.
Dec 25, 2017

Hello,

What is the error?

Alexey Matveev
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.
Dec 25, 2017 • edited

It shoud be like that

attachmentManager.getAttachments(issue).each
{(it.getFilename().endsWith(".xlsx"))}

 

 

Thanks @Alexey Matveev

Code error resolved, But any File(even excel file with xlsx Suffix) attach in Create screen , Displays an Error Message in create issue and issue dont create.

How do Resolve it?

ٍErroe message is in script validator screen.

2.PNG

Alexey Matveev
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.
Dec 26, 2017

What validator do you use? 

Alexey Matveev
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.
Dec 26, 2017

The problem is that a validator must return true or false. Your validator returns null. And your validator never works. You should do something like this

def flag = true

attachmentManager.getAttachments(issue).each
{ if (!it.getFilename().endsWith(".xlsx")) {
  flag = false;
}
}
return flag

I did not check the code. But I think you have the idea. Or maybe the code will work, who knows :)

I run this code but the error message is still displayed and issue is not created.

Alexey Matveev
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.
Dec 26, 2017

Ok.

You can not use attachmentManager.getAttachments(issue) to get the newly added files to the issue. This method get attachements from already existing issues that is why if you look in your logs you will see NPE.

If you want to get newly added files then follow this guide

https://scriptrunner.adaptavist.com/5.2.4/jira/recipes/workflow/validators/validate-attachments-links-in-transition.html#_validating_attachments_added_this_transition

But I could not make it work on the create issue transition.

Hi @Alexey Matveev

The error message is still displayed
I do not know what to do?

When I use script examples in validators،They also do not work correctly ,

55.PNG

Alexey Matveev
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.
Jan 03, 2018 • edited

I gave you a link on how it should work. As I said in my previous post I was not able to make it work on the Create screen within 20 mins. Maybe it is not supposed to work for the Create screen. I would like to help you but unfortunately I do not have time right now. I would advise you to ask Adaptivist ScriptRunner support why the article does not work for you.

Alexey Matveev
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.
Jan 03, 2018

You should ask Adaptivist ScriptRunner support not Atlassian. If you find out what was the problem kindly provide your answer here. I would like to know the answer as well.

Good luck! :)

thanks very very much @Alexey Matveev

<3<3

TAGS
AUG Leaders

Atlassian Community Events