Last active
April 2, 2020 06:57
-
-
Save JiBrok/def78831a2e8d96b7e2fdd808b09adaf to your computer and use it in GitHub Desktop.
JiBrok, message field, JavaScript Example: update and hide message with 2 conditions by select fields(Service Desk)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['jquery'], function($) { | |
function setMessage(title, body, messageType){ | |
var jsonMessage = {} | |
jsonMessage.title = title | |
jsonMessage.body = body | |
jsonMessage.messageType = messageType | |
jsonMessage.jibrokMessageKey = true //Require for Service Desk | |
$('#' + CF_ID_MESSAGE).text(JSON.stringify(jsonMessage)).trigger('change')//Service Desk create request | |
} | |
function showMessage(isShow){ | |
if(isShow){ | |
$('.field-group:has(#'+ CF_ID_MESSAGE + ')').find('.aui-message').show() | |
//$('#' + CF_ID_MESSAGE).show() //for Message type: Show as is | |
} else { | |
$('.field-group:has(#'+ CF_ID_MESSAGE + ')').find('.aui-message').hide() | |
//$('#' + CF_ID_MESSAGE).hide() //for Message type: Show as is | |
} | |
} | |
function getFieldValue(fieldId) { | |
return $('#' + fieldId).val() | |
} | |
//EDIT HERE | |
var CF_ID_MESSAGE = 'customfield_10013'//set custom field id(Message field) | |
var CF_ID_SELECT1 = 'customfield_10200'//set custom field id(Select field) | |
var CF_ID_SELECT2 = 'customfield_10201'//set custom field id(Select field) | |
var OPTION_ID_HIGH = '10100'//set option id(view in select field config - CF_ID_SELECT1) | |
var OPTION_ID_AFFECTED_ALL_USERS = '10103'//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 | |
showMessage(true) | |
} else { | |
showMessage(false) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment