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

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 Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

50 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