Hi Community,
How can auto-check one option for a custom checkbox field in Service Management? For example, I have a custom check box field and it has three options "Notification1" "Notification2" and "Notification3". I want option three to be selected whenever a customer tries to create a request. The other two options are optional they can select or disregard but one option should be selected all the time. I tried the below behavior short script. It checked the option, but the issue is the other two options are not checkable. Is it possible to have an option auto-select and the other two can be manually selected if needed?
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def notify = getFieldById('customfield_17560')
notify.setFormValue('Notification3')
Thanks,
There are some recent improvements to behaviours that I've not yet experimented with that might make this simpler.
But in older versions, you have to use the option id with setFormValue on Select and Checkbox fields. And for checkbox and multiselect, you have to offer an array of optionId.
Try this script:
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def notifyFormField = getFieldById('customfield_17560')
def notifyCf = ComponentAccessor.customFieldManager.getCustomFieldObject(notifyFormField.fieldId)
def config = notifyCf.getRelevantConfig(issueContext)
def options = ComponentAccessor.optionsManager.getOptions(config)
notifyFormField.setFormValue([options.find{it.value == 'Notification3'}.optionId])
Hi @Peter-Dave Sheehan it works, I'm seeing the third option is checked when I try to create a request, however, the only issue is that I can't check the other two options manually. The goal is that 3rd option should be always auto check and the user should be able to check the other two options manually. Any idea why it's not letting me check the other two options?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you toggle the "read-only/editable" switch on the behaviour configuration?
Can you share a screenshot of the behaviour screen?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter-Dave Sheehanmy bad I was adding code on server-side-script for the notify custom field. I removed the code from notify field and added code on Initialiser and it worked.
Now I'm trying to display an error message if someone uncheck the option. I added the below code, the issue is when the page loads the error is already there. If uncheck and check it back then the error goes away. I added the if condition part in the server-side script but nothing got changed. Is it possible to add the error if someone uncheck the option?
if(notifyFormField.value != 'Notification3') {
notifyFormField.setError('Notification3 option is mandetory, it has to be check in order to create a request. The other two options are optional.')
}
else {
notifyFormField.clearError()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Put the script to set the default value in the Initializer.
Then, add the script to display the error in the field's server-side script.
But you need to check that 1 or the values are Notification3.
Try something like this:
def notifyFormField = getFieldById('')
notifyFormField.clearError()
def notfiyValues = (notifyFormField.value ?: []) as List
if(!notfiyValues.contains('Notification3') {
notifyFormField.setError('Notification3 option is mandetory, it has to be check in order to create a request. The other two options are optional.')
}
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.
Hi @Shah Baloch ,
Under field configuration, You can make the field value as a default so it will be always checked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Manoj Gangwar, I already tried that, but the issue is it leaves the option checked from the backend of the service desk, which we don't want since sometimes we create tickets using the backend for internal tasks. We just wanted to check for the portal I thought it might be achieved using Scriptrunner.
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.