Missed Team ’24? Catch up on announcements here.

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

KCF-Pro Custom Field Pre-populate from Java Script

Justin Rush February 26, 2016

I have a question related to

I'm trying to pre-populate a KCF - Autocomplete Multiple set to Issue Picker with a default issue using AJS as it is a hard constraint.

AJS.$("#customfield_XXXX").select2("val""");

Using the call above seems to be the best approach for me. I have an issue id and am confused about the format of "" in the select2("val""") portion of the call. I have a JIRA id of TST-1234

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Alexandra Topoloaga
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.
February 28, 2016

Hi,

Since you want to set an issue picker (an not a default renderer), it won't be that simple. The options are not stored as strings (as in String (default) case). They are JSONs. with the next structure:

 

meta: {
href: the url to the issue
iconUrl: the icon url
labelOverride: the issue key
longLabel: the issue key and the issue summary
shortLabel: the issue key
tooltip: the issue summary
}
option: {
label: ""
value: the issue id
}

 

In order to set your field, you should do something like this:

var temp = [];
temp.push("{\"meta\":{\"longLabel\":\"TST-5 - 888\",\"tooltip\":\"888\",\"shortLabel\":\"TST-5\",\"iconUrl\":\"/secure/viewavatar?size=xsmall&avatarId=10316&avatarType=issuetype\",\"href\":\"http://localhost:7005/browse/TST-5\",\"labelOverride\":\"TST-5\"},\"option\":{\"label\":\"\",\"value\":\"10303\"}}");
AJS.$("#customfield_10700").select2("val", temp);


However, if you have JJUPIN, the most easy way to do this is by using Live Fields. All you have to do is to write a line like below, without worrying that the field is or is not a select2, or if it's an issue picker or an user picker.

lfSet("customfield_10700", "TST-5");


Hope this helps,
Alexandra

0 votes
Justin Rush February 29, 2016

I was able to get it to work using the JSON format that you provided with one caveat.

Select2 did not alter the field but the format .val(...).change(); worked

AJS.$("#customfield_10700").val("{\"meta\":{...}}").change();

TAGS
AUG Leaders

Atlassian Community Events