Skip to content

Instantly share code, notes, and snippets.

@JiBrok
Last active September 4, 2020 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JiBrok/1d308d9e393c739790462d35b5cdb305 to your computer and use it in GitHub Desktop.
Save JiBrok/1d308d9e393c739790462d35b5cdb305 to your computer and use it in GitHub Desktop.
JiBrok, message field, JavaScript Example: The script will check the custom fields on the view issue screen. If all fields are empty, the message banner will be hidden.
function checkFieldsAreEmptyAndHideMessage(fieldIds, messageFieldId){
AJS.$.ajax({
url: AJS.contextPath() + '/rest/api/2/issue/' + JIRA.Issue.getIssueId() + "?fields=" + fieldIds.join(),
type: "GET",
async: false,
success: function(issue) {
if(areAllFieldsEmpty(issue, fieldIds)){
hideMessage(messageFieldId)
}
}
});
}
function hideMessage(messageFieldId){
AJS.$("#rowFor" + messageFieldId).hide()
}
function areAllFieldsEmpty(issue, fieldIds){
for(var i = 0; i < fieldIds.length; i++){
var fieldId = fieldIds[i]
if(issue.fields[fieldId] != null){
return false
}
}
return true
}
//The script will check the custom fields on the view issue screen. If all fields are empty, the message banner will be hidden.
if(JIBROK_MESSAGE_FIELD_CONTEXT == "VIEW_ISSUE"){//version 3.1.7+ or set JavaScript context - Issue view screen
var customFieldIds = ["customfield_10201", "customfield_10202"]//fields will be check on null value
var messageFieldId = "customfield_10013"
checkFieldsAreEmptyAndHideMessage(customFieldIds, messageFieldId)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment