Forums

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

Possible to clear Insight/Asset field using ScriptRunner Behaviour

Batuhan ŞEN February 1, 2023

Hi everyone,

I am trying to clear Insight field on create screen.

When you select any Component, Insight field fetches data according to Component. If you select any result and then if component changes, data will be changed but u have to select manually new result. (It still keeps old data)

Although Insight Field is required, data is wrong(previous selection value), you can create on this point. I want to clear Insight Field value when component is changed. I am trying Script Runner Behaviour now. 

.setFormValue("A-1") is working with specific Object ID. But when I use .setFormValue("") or .setFormValue(null) etc. It did not work.

How can I handle this? Is it possible on Insight fields? Anyone knows?

Thanks,
My Regards

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2023 edited

Hi @Batuhan ŞEN

I have done a basic test in my environment, and I don't seem to be encountering any problems.

Below is the sample working code that I have tested with:-

import com.atlassian.jira.bc.project.component.ProjectComponentImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def components = getFieldById(fieldChanged)
def componentsValue = components.value as List<ProjectComponentImpl>
components.clearError()

def insightField = getFieldByName('Support Engineer')
insightField.setFormValue(null)

componentsValue.each {
if (componentsValue.size() == 1) {
if ( it.name == 'Animation') {
insightField.setFormValue('SS-1')
} else if (it.name == 'Database') {
insightField.setFormValue('SS-2')
} else if (it.name == 'Server') {
insightField.setFormValue('SS-3')
} else if (it.name == 'UI') {
insightField.setFormValue('SS-4')
}
} else if (componentsValue.size() == 2) {
if (it.name in ['Animation', 'Database']) {
insightField.setFormValue(['SS-1', 'SS-2'])
} else if (it.name in ['Animation', 'Server']) {
insightField.setFormValue(['SS-1', 'SS-3'])
} else if (it.name in ['Animation', 'UI']) {
insightField.setFormValue(['SS-1', 'SS-4'])
} else if (it.name in ['Database', 'Server']) {
insightField.setFormValue(['SS-2', 'SS-3'])
} else if (it.name in ['Database', 'UI']) {
insightField.setFormValue(['SS-2', 'SS-4'])
} else if (it.name in ['Server', 'UI']) {
insightField.setFormValue(['SS-3', 'SS-4'])
}
} else if (componentsValue.size() == 3) {
if (it.name in ['Animation', 'Database', 'Server']) {
insightField.setFormValue(['SS-1', 'SS-2', 'SS-3'])
} else if (it.name in ['Animation', 'Database', 'UI']) {
insightField.setFormValue(['SS-1', 'SS-2', 'SS-4'])
} else if (it.name in ['Database', 'Server', 'UI']) {
insightField.setFormValue(['SS-2', 'SS-3', 'SS-4'])
}
} else if (componentsValue.size() == 4) {
insightField.setFormValue(['SS-1', 'SS-2', 'SS-3', 'SS-4'])
}
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

I have configured the Insight Asset to a Multi-Select list in the sample above. Hence, the additional conditions are added based on the Component/s size.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

 

Below are a couple of test screenshots. They display the option selected in the Insight Field according to the option set in the Component/s field.

test1.png

test2.png test3.png

test4.png

I all options are selected from the Component/s list, all the options will be selected in the Insight Asset field as well as shown below:-

test6.png

 

If the Component/s field is reset, i.e. empty, the Insight field is also empty accordingly, as shown below:-

test5.png

 

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

 

Batuhan ŞEN February 3, 2023 edited

Hi @Ram Kumar Aravindakshan _Adaptavist_,

Thank u.

I tried it but it did not work. Actually, this Insight field configured as 

Filter Issue Scope (IQL): Component=${components.label}, because so many objects on the scheme.

For example, I selected one and I removed or selected new one. Field keeps old value. And I have to select manually. setFromValue(null) did not work.

Actual result is No Matches. Even required, you can create because it keeps old one :)

Thank u again,

My Regards

1.png

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 6, 2023

Hi @Batuhan ŞEN

Could you do a quick test and add a log parameter to see the value returned in the Insight Assets field?

I'm not sure if it returns the Insight key alone. This could be possibly why it is not working on your end.

Thank you and Kind regards,
Ram

Batuhan ŞEN February 7, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

It is working now. When I tried to use getFieldById("customfield_xxxxx") instead of getFieldByName(), it worked.

Thank u for your support :)
Kind Regards,
Batu

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, dance, gamification, badge, razzle dazzle, team '25 anaheim

Earn a one-day badge today and do the Atlazzle Dazzle! 🕺

Today only! Share what you’re the most excited about for Team ‘25 or just dance out the beginning of a new quarter with us.

Comment the post
AUG Leaders

Atlassian Community Events