Created
September 22, 2017 03:31
-
-
Save jacebenson/f6519532121a9d9de6cd482b645d460e to your computer and use it in GitHub Desktop.
Show Hints for choice lists
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
//script include global.choiceUtil | |
//client callable true | |
var choiceUtil = Class.create(); | |
choiceUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, { | |
getHint: function() { | |
try { | |
var returnObj = {}; | |
var hint = new GlideRecord('sys_choice'); | |
hint.addQuery('name', this.getParameter('sysparm_table')); | |
hint.addQuery('field', this.getParameter('sysparm_field')); | |
hint.addQuery('value', this.getParameter('sysparm_val')); | |
hint.addQuery('inactive', 'false'); | |
hint.query(); | |
if (hint.next()) { | |
returnObj.hint = hint.getValue('hint'); | |
} else { | |
returnObj.error = 'no choice found for ' + hint.getEncodedQuery(); | |
} | |
return JSON.stringify(returnObj); | |
} catch (error) { | |
return JSON.stringify(error, '', ' '); | |
} | |
}, | |
type: 'choiceUtil' | |
}); |
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
function onChange(control, oldValue, newValue, isLoading, isTemplate) { | |
if (isLoading || newValue === '') { | |
return; | |
} | |
var field = 'category'; | |
var ga = new GlideAjax('global.choiceUtil'); | |
ga.addParam('sysparm_name', 'getHint'); | |
ga.addParam('sysparm_table', 'incident'); | |
ga.addParam('sysparm_field', field); | |
ga.addParam('sysparm_val', newValue); | |
ga.getXML(HintParse); | |
function HintParse(response) { | |
var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer")); | |
//console.log(answer); | |
g_form.hideFieldMsg(field, true); | |
if (answer.hint) { | |
g_form.showFieldMsg(field, answer.hint, 'info', true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment