Missed Team ’24? Catch up on announcements here.

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

Simple script validator not working in Service Desk

Joel Batac 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

0 votes
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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 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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events