Hi,
We have a radio button field, if it is yes then it should check whether is there any attachment in the smart attachment field
Smart attachment has category in its attachment field, we will have to check if the attachment is present in that attachment category
Then if both mentioned above are yes then the transition should happen else it should throw error message 'Upload attachment'
Remember if radio button field has NO in it, then it should not restrict the transition, it is only if it is yes then it should check for attachment and throw error.
Current script is not working, and it is attached here, can you pls help with this?
Below is the script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.AttachmentManager
//Get the issue and the custom field value
Issue issue = issue
def customFieldValue = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("LLD Configuration Requirement"))
// Check if the custom field is "yes"
if (customFieldValue == "Yes") {
// Get the attachment manager
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()
// Check if the issue has attachments
if (attachmentManager.getAttachments(issue).isEmpty()) {
// If there are no attachments, throw an error return false
}
}
//If the custom field is not "yes" or there are attachments, allow the transition return true
Regards.
Hi @SysAdmin
Please clarify what approach you are trying to use to perform the validation.
Are you using Behaviour or the Workflow Validation? If it's the former you will need to use the Server-Side Behaviour and set it for the transition screen. If it's the latter, then it would be best if you use the Custom Script Validator.
Also, please clarify, are you trying to perform this validation using the standard Jira dialog or via the JSM Portal?
I am looking forward to your feedback and clarification.
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_
Thanks for the reply!
I used a custom script validator for this purpose.
As per the use case I had to script it as below and which is working.
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.stiltsoft.jira.attachcategory.facade.SmartAttachmentsFacade
import com.stiltsoft.jira.attachcategory.facade.entity.issue.AttachmentCategories
import com.stiltsoft.jira.attachcategory.facade.entity.issue.AttachmentCategory
@WithPlugin("com.stiltsoft.jira.smart-attachments")
SmartAttachmentsFacade facade = ScriptRunnerImpl.getPluginComponent(SmartAttachmentsFacade)
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField customfield_A = customFieldManager.getCustomFieldObject("customfield_Id")
Option customFieldValue = (Option) issue.getCustomFieldValue(customfield_A)
String customFieldValueRaw = customFieldValue.getValue()
CustomField customfield_B = customFieldManager.getCustomFieldObject("customfield_Id")
Option customFieldValue1 = (Option) issue.getCustomFieldValue(customfield_B)
String customFieldValueRaw1 = customFieldValue1.getValue()
CustomField customfield_C = customFieldManager.getCustomFieldObject("customfield_Id")
Option customFieldValue2 = (Option) issue.getCustomFieldValue(customfield_C)
String customFieldValueRaw2 = customFieldValue2.getValue()
CustomField customfield_D = customFieldManager.getCustomFieldObject("customfield_Id")
Option customFieldValue3 = (Option) issue.getCustomFieldValue(customfield_D)
String customFieldValueRaw3 = customFieldValue3.getValue()
log.warn"customFieldValueRaw= "+customFieldValueRaw+"customFieldValueRaw1"+customFieldValueRaw1+"customFieldValueRaw2"+customFieldValueRaw2+"customFieldValueRaw3"+customFieldValueRaw3
if (customFieldValueRaw.equals("Yes") || customFieldValueRaw1.equals("Yes") || customFieldValueRaw2.equals("Yes") || customFieldValueRaw3.equals("Yes")) {
AttachmentCategories attachmentCategories = facade.getAttachmentCategories(issue)
AttachmentCategory serverCategory = attachmentCategories.getCategories().find { category -> category.getName() == "smart attachmnt category name" }
log.warn"serverCategory= "+serverCategory
def tempAttachmentsCount = serverCategory.getTempAttachments().size()
log.warn"tempAttachmentsCount= "+tempAttachmentsCount
def actualAttachmentsCount = serverCategory.getAttachments(true).size()
log.warn"actualAttachmentsCount= "+actualAttachmentsCount
if (tempAttachmentsCount == 0 && actualAttachmentsCount == 0) {
throw new InvalidInputException("There is no attachment in the category")
}
}
Regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.