How to create a custom field like Components field?

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Hey, guys!

What I want is to create custom button which is the same like Component/s button:

Components field.png
So I need to have the content of Component/s button and behaviour of Component/s button in custom button.


I've tried to create a custom button and put this code inside of "Description":


(function($){
new AJS.MultiSelect({
element: $("#customfield_10653"),
itemAttrDisplayed: "label",
errorMessage: AJS.params.multiselectComponentsError
});
})(AJS.$);

 

However, the above code is not working and I see just the above code.

Guys, how can it possible to create custom field like "Component/s" button?

 

I have an option to use ScriptRunner.

3 answers

0 votes
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Hello @zaharovvv_suek_ru

As I can remember, you are using scriptrunner

Component/s field it's just like labels field, so why not try to create labels field that will be populated from components via listener on Issue Update event?

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

@Mark Markov yeah, you are right! 

Thanks for your reply.

It sounds really good. However, I am not really aware how it is possible to populate by components and what does "via listener on Issue Update" event. Could you be very kind to clarify that?

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

Jira based on event architecture. When something happens(changes) in system, jira thtows an specific event(for example, when you made some changes to the field values, jira throws ISSUE_UPDATED event), that can be caught and processed by listeners. To make listener with Scriprunner go to add-ons -> Script listeners -> Add -> Custom script listener

Project key: What project lister will be affect

Event: On what event it will be triggered (in your case Issue Updated)

Inline/file script: And your script that will do all kind of magic you need.

Here is example of script that will catch changes of Component/s field:

def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Component"}

if (change) {
    log.debug "Value changed from ${change.oldstring} to ${change.newstring}"
 // your actions if the field has changed
}
zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

@ Huge thanks! You make it clearer! Now it is really clear about events. 

However, is it possible:

1. To get components and populate custom field by this components? I mean like Components field.

2. To have behaviour like Components field - when I input letter in custom field, then autosuggestion of components will work?

Like kamrulhussain likes this
Nasreen Shaikh November 18, 2020

 Hello @zaharovvv_suek_ru ,

Did this work in your case , coz I am also having similar requirement, if not, then what was the thing that worked.

Thanks in Advance,

Nasreen

Like Nicholas Shaw likes this
0 votes
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2018

@zaharovvv_suek_ruYou don't need to  create a  new one,  we have the component/s

field,  

  • Just go to knowledge base here see how to  Configure component
  • this values  for the component  will  appear on the screen as you already have this  field  added to screen .

 

Why you  want to  complicate things ?

 

Best!

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

@Moses Thomas yeah, I know, however I was asked by my chief to create the same custom field "ComponentsLinked" which looks exactly the same like "Component/s" field and set Components value  in that custom field. 

So I cannot protest to his requirements.

Is it possible to create such a field?

Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2018

@zaharovvv_suek_ruI think its not designed for you to  add a system field.

0 votes
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 13, 2018

@zaharovvv_suek_ru

Please KB article on  how to add new custom field Add custom field

What  do  you  hope to  achieve?  component field is a system  field  by  default.

 

Best

zaharovvv_suek_ru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2018

Thanks for your reply, Moses. I can add custom field, however I cannot create a custom field which is populated by components.

 

What I want is to create custom field "ComponentsLinked" which looks exactly the same like "Component/s" field and set Components value  in that custom field. 

How can I do it?

Suggest an answer

Log in or Sign up to answer