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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I put javascript code to spice up a multi select custom field I am creating in a plugin.

Hi,

I am creating a multiselect field via a plugin. I would like to put javascript code as description when creating the plugin to make the field look fancy (actually behave like the nice components field of JIRA)

I want to pass the below code as a description parameter when creating the custom field.

(function($){
new AJS.MultiSelect({
element: $("#customfield_10052"),
itemAttrDisplayed: "label",
errorMessage: AJS.params.multiselectComponentsError
});
})(AJS.$);
The problem is that the above code needs the custom field ID. However I dont know the field ID till the field is created by the statement below.
CustomField cField = CustomFieldManager.createCustomField(customfieldName, "FIELD DESCRIPTION: JAVA SCRIPT CODE HERE", customFieldManager.getCustomFieldType(customFieldTypeKey) , customFieldSearcher, contexts, issueTypes);

So I can only get the ID using cField.getID() after the field is created.

So How can I use the above javascript code as description of the multiselect custom field I am creating in the plugin.

1 answer

1 accepted

You can set the description after the field is created.

String jscode = "(function($){...";
cField.setDescription(jscode);
CustomFieldManager.updateCustomField(cField);

Hey boris . I was about to delete my question as I just realized myself customField would probably have a setDescription function.

Thanks though!

Hey Boris. Strangely enough I am able to set the Description of the field when I send some text in to cField.setDescription(someTextStringHere), however when the string holds some java script code (with proper formatted escape characters ofcourse) it does not show up in the acutal field description, while the text does show.

Any ideas if Jira even allows us to set java script as description via plugins or am I missing something?

Jira allows setting js code in the description. I think you do not need to escape it. The script will not show up in the description but it's there. You can do a simple test by putting <script>console.log('test message')</script> and check if it will show up in the browser console.

https://confluence.atlassian.com/display/JIRA/Fields+Allowing+Custom+HTML+or+JavaScript

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Happy New Year and Welcome New Marketplace Partner Program Partners!

Happy New Year! We hope you all had a safe and restful holiday season. 2020 was a unique year full of unforeseen events; however, as we enter the new year of 2021, we’re optimistic for the light at t...

444 views 5 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you