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

Setting default value on Asset custom field (multiple checkbox) using a ScriptRunner Behavior

Matt Donnelly November 21, 2023
ScriptRunner 8.16.0
JSD 5.4.11

Hello,
I can’t get an Asset custom field (multiple checkbox) to populate with default values using a ScriptRunner Behavior in JSD.

The script is basic, I'm just trying to manually set an option via its label:
def field = getFieldByName("CRM related products")
field.setFormValue(["Catalyst"])
The Asset custom field's Filter Scope AQL is objectType = "Products", which is just a schema with ~16 objects.
I've tried using the label ("Catalyst"), the option value ("ACMDB-1"), and the ObjectBean(?) name ("Catalyst (ACMDB-1)").
When the screen renders, there's a brief flash of the string "Catalyst" in a select field, which disappears, but then the select field checklist items render. I checked that field element in the inspector, and it was set to display: none. Unhiding it showed me the passed value:
Screenshot 2023-11-21 130616.png

If anyone can tell me me what I'm missing I'd be very appreciative.
Best, 
Matt

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
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.
November 25, 2023

Hi @Matt Donnelly

Welcome to the community.

Could you please clarify if you have tried using ScriptRunner's HAPI feature to set the value for the Assets field?

If not, I suggest looking at the Assets section in the ScriptRunner HAPI documentation. There are a couple of examples in the documentation which show how you can use HAPI to manage the assets.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

Matt Donnelly November 27, 2023

Hi Ram, thanks for replying.

Yes, I am using HAPI. What I want to do is populate an Assets custom field service desk screen (shown in my first post) with values from Assets. So the process would be:

  1. customer clicks on a request type
  2.  A new request type screen appears, with an Assets custom field
  3. A ScriptRunner Behavior script runs, which pre-populates checkboxes with values from Assets.

The code in my initial post (which I took from the Behaviors Setting Field Defaults page) works fine if the Assets custom field is set to multiple select. But for me the same code does not work if the field is multiple checkbox

Here's a step by step:

 

1. I set up a Behavior with the following code. Note that the value "ACMDB-1" has the Label "Catalyst" in Assets:

behavior.png

2. I created an Assets Custom Field with the following configuration (Select & Multiple):

 

select.png

3. The default is populated correctly when the Request screen is initialized:

 

works.png

 

4. However, if I change the Assets custom field configuration to Checkbox...

 

checkbx.png

 

5. The "Catalyst" checkbox is not checked:

 

doesnt-work.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.
December 4, 2023

Hi @Matt Donnelly

Thanks for providing the requested information.

I will review it and get back to you once I have an update.

Thank you and Kind regards,

Ram

TAGS
AUG Leaders

Atlassian Community Events