After Jira upgrade from 4.4.3 to 5.1.4 custom field that uses Javascript to populate user picker field does not work.

Mark Tuttle
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 8, 2012

The way the script was written, the custom fields don't get populated until after the page is created, by design. This web service requires you to select a person in a "people picker" field, then when you tab off of the field, it fires off the call to the web service. After the 5.1 update this doesn't work any longer either in the "quick create" or just the standard windowed create screen.

The code for the custom field.

<script type="text/javascript" src="http://webprod4.mutualofomaha.com/JIRAIntService/js/JIRAIntService.js">
</script>

<script type="text/javascript">

var updater = new com.mutualofomaha.ldap.LdapUpdater();
updater.pageLoad('reporter', {'customfield_10652': ['employeeOperation'], 'customfield_10653': ['employeeDivision']});
updater.populateFields('reporter', {'customfield_10652': ['employeeOperation'], 'customfield_10653': ['employeeDivision']});

</script>


The javascipt that is called:

var com = {};
com.mutualofomaha = {};
com.mutualofomaha.ldap = (function namespace(){
var fieldMap = {};

function LdapUpdater(){
this.fieldMap = fieldMap;
}

LdapUpdater.prototype.pageLoad = function pageLoad(triggerField, fieldMaps){
// Handler for .ready() called.
//call the service for page load with no change.
var triggerFieldId = triggerField;
var fieldMaps2 = fieldMaps;
connectToService(triggerFieldId, fieldMaps2);

}

LdapUpdater.prototype.populateFields = function populateFields(triggerField, fieldMaps){
AJS.$('#'+triggerField).change(function(){
var triggerFieldId = triggerField;
var fieldMaps2 = fieldMaps;
connectToService(triggerFieldId, fieldMaps2);

});

AJS.$('#'+triggerField).blur(function(){
var triggerFieldId = triggerField;
var fieldMaps2 = fieldMaps;
connectToService(triggerFieldId, fieldMaps2);

});
}

function connectToService(triggerFieldId, fieldMaps) {
fieldMap[triggerFieldId] = fieldMaps;
var triggerFieldValue = AJS.$('#'+triggerFieldId).val();
AJS.$.ajax({
//url: "http://webprod4.mutualofomaha.com/EntLDAPRestService/home/getLdapAttributes/" + triggerFieldValue +".json",
url: "http://webprod4.mutualofomaha.com/JIRAIntService/home/getPSAttributes/" + triggerFieldValue +".json",
dataType: "jsonp",
data: {trigger:triggerFieldId},
jsonp : "callback",
jsonpCallback: "com.mutualofomaha.ldap.updateField",
contentType: "text/json"

});
}

return {LdapUpdater: LdapUpdater, updateField: function updateField(returnData) {
var ldapPerson = returnData["1"];
var triggerField = returnData["2"];
var fieldMapsInstance = fieldMap[triggerField];
AJS.$.each(fieldMapsInstance, function(key, value){
var concattedVals = "";
var count = 0;
AJS.$.each(value, function(index, propertyVal){
if (count == 0) {
concattedVals = ldapPerson[propertyVal];
} else {
concattedVals = concattedVals + " " + ldapPerson[propertyVal];
}
count = count+1;
})

AJS.$('#'+key).val(concattedVals);
});
}};
}());

This code has worked fine until the upgrade.

1 answer

1 accepted

0 votes
Answer accepted
Harry Chan
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.
October 9, 2012

Hi, there were changes to how Javascript works from JIRA 4.4 to JIRA 5.x.

Refer to https://developer.atlassian.com/display/JIRADEV/Custom+Fields+that+use+CSS+or+JavaScript+Web+Resources+in+JIRA+5.0 for more information on the changes.

In particular, you need to change the function to:

&lt;script type="text/javascript"&gt;
function action() {
}
action();
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context) {
  action();
});
&lt;/script&gt;

Mark Tuttle
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 24, 2012

Harry,

Sorry for the delay. It worked. many Thx... mark

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events