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

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

This widget could not be displayed.

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;

Harry,

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

733 views 0 3
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you