Verify attachment length Script Runner Cloud

Daniel Alonso June 8, 2021

Hi,

I created a Fast-track Post Function that verifies if there are any attachments on the Issue and if there aren't, it transitions the issue, this is what I have on the 

I tried with both conditions below but I had the same error.

021-06-08 16:55:42.661 ERROR - Cannot get property 'length' on null object on line 1
condition:issue.fields.attachments.length == 0
condition:issue.attachments.lenght == 0

 Any suggestions?

By the way,  issue.attachments.lenght is valid on the Expression Tester App.

Daniel

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2021

Hi @Daniel Alonso , you have typo in your condition.

You have:

  • lenght 

but it should be

  • length 
Daniel Alonso June 9, 2021

I change it and it keeps showing the error:

2021-06-08 16:55:42.661 ERROR - Cannot get property 'length' on null object on line 1
2021-06-08 16:55:42.675 ERROR - Class: com.adaptavist.sr.cloud.workflow.FastTrackIssue, Config: [className:com.adaptavist.sr.cloud.workflow.FastTrackIssue, uuid:71369c1f-0147-4c52-b5de-899a697c2046, enabled:true, executionUser:ADD_ON, condition:issue.attachments.length == 0, description:, additionalCode:, comment:Attachment is mandatory, please review, transitionId:101, transitionName:Back to Hiring Manager, accountId:XXXX]
Daniel Alonso June 9, 2021

I also tried with a filter option that actually works on the Expression Tester but on the fast-track condition doesn't:

 

021-06-09 12:58:10.292 ERROR - startup failed:
Script1.groovy: 1: unexpected token: > @ line 1, column 38.
   issue.attachments.filter(attachment => attachment.mimeType == 'application/pdf').length > 0
                                        ^

1 error

2021-06-09 12:58:10.309 ERROR - Class: com.adaptavist.sr.cloud.workflow.FastTrackIssue, Config: [className:com.adaptavist.sr.cloud.workflow.FastTrackIssue, uuid:71369c1f-0147-4c52-b5de-899a697c2046, enabled:true, executionUser:ADD_ON, condition:issue.attachments.filter(attachment => attachment.mimeType == 'application/pdf').length > 0, description:, additionalCode:
, comment:Attachment is mandatory, please review, transitionId:101, transitionName:Back to Hiring Manager, accountId:XXXX]

 Screen Shot 2021-06-09 at 9.01.47 AM.png

Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 9, 2021

Hi @Daniel Alonso I just tested it and if validator does not pass, email notification comes to my email inbox with message:

Selection_336.png

And my validator looks like:

Selection_337.png

Do you have similar configuration?

Daniel Alonso June 10, 2021

Thanks @Martin Bayer _MoroSystems_ s_r_o__ 

I cannot use a regular SR validator, or even a jira workflow validator/condition because I want to block an approval transition and right now it is not being blocked, even with a built-in validation/condition. That's why I used the Fast-track transition to catch if the issue doesn't have any attachment go back to the approval status.

Can you please try on your end using a Fast-track transition, then you will see what I'm talking about.

Thanks, Daniel

Suggest an answer

Log in or Sign up to answer