Skip to content

Instantly share code, notes, and snippets.

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/56feb2f4510b5b435366329d671df0a8 to your computer and use it in GitHub Desktop.
Save JiBrok/56feb2f4510b5b435366329d671df0a8 to your computer and use it in GitHub Desktop.
JiBrok, message field, JavaScript Example: update and hide message with 2 conditions by select fields
require(['jquery'], function($) {
function setCFValue(customfield_id, value){
$('#' + customfield_id).val(value).trigger('change')
}
function setMessage(title, body, messageType){
var jsonMessage = {};
jsonMessage.title = title;
jsonMessage.body = body;
jsonMessage.messageType = messageType;
setCFValue(CF_ID_MESSAGE, JSON.stringify(jsonMessage))
}
function getFieldValue(fieldId) {
return $('#' + fieldId).val()
}
//EDIT HERE
var CF_ID_MESSAGE = 'customfield_10017'//set custom field id(Message field)
var CF_ID_SELECT1 = 'customfield_10015'//set custom field id(Select field)
var CF_ID_SELECT2 = 'customfield_10016'//set custom field id(Select field)
var OPTION_ID_HIGH = '10000'//set option id(view in select field config - CF_ID_SELECT1)
var OPTION_ID_AFFECTED_ALL_USERS = '10003'//set option id(view in select field config - CF_ID_SELECT2)
updateMessage()
$('#' + CF_ID_SELECT1).on('change', function(){updateMessage()})
$('#' + CF_ID_SELECT2).on('change', function(){updateMessage()})
function updateMessage(){
if(getFieldValue(CF_ID_SELECT1) === OPTION_ID_HIGH && getFieldValue(CF_ID_SELECT2) === OPTION_ID_AFFECTED_ALL_USERS){//or replace on your options
setMessage('High!', 'text for High and Affected all', 'error')//set message config
} else {
//empty message not showing
setMessage('', '', '')
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment