The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Simple script validator not working in Service Desk

Joel Batac
Contributor
November 16, 2022

HI,

 So I have the below script (which i saw in the community) working in my regular/software jira but it's not working on my service desk portal. Any idea/help?

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.AttachmentSystemField
import webwork.action.ActionContext

def attachmentFiles = ActionContext.request?.getParameterValues(AttachmentSystemField.FILETOCONVERT)
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_22112")
log.warn(customField)
def CFvalue = (String)issue.getCustomFieldValue(customField)
log.warn(CFvalue)

if(CFvalue == "Yes" && attachmentFiles.size() < 2) {
return false
}
else {
return true
}

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Joseph Chung Yin
Community Champion
November 16, 2022

@Joel Batac -

Hi Joel:

One of the reasons why it may not work via the portal UI -

1) For the customfield the script is using - Does it available in your Request Type setup? + your JSM project's issue setup?

It will be great if you can share with us what is the error being throw.

Hope this helps.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Infrastructure Applications Team

Viasat Inc.

Joel Batac
Contributor
November 16, 2022

yes it does...by the way i modified the script and it's working now


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

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_22112")
def CFvalue = (String)issue.getCustomFieldValue(customField)
def issue2 = issue as MutableIssue

def newAttachmentNames = issue2.modifiedFields.get(IssueFieldConstants.ATTACHMENT)?.newValue as List

if(CFvalue == "Yes" && newAttachmentNames.size() < 2) {
return false
}
else {
return true
}

Joseph Chung Yin
Community Champion
November 16, 2022

@Joel Batac -

Thanks for sharing the updated code.  Glad it is working for you now.

Didn't realize that you are using the script when the issue is being modified.

Best, Joseph

TAGS
AUG Leaders

Atlassian Community Events