- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2016 12:02 PM
So I've got it to return the variables, but it's still only pulling ones thats are actually marked as mandatory vs ones changed to mandatory via UI policy.
I put it in an onChange script instead, but even if I run it after the page loads it doesn't pull the ones affected by the UI policy. Any suggestions? The code is running fine, but I think I just need to see if there is a way to check if a UI policy is affecting the variables. Below is my code so far:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == 3) {
var ga = new GlideAjax('mandatoryVariables');
ga.addParam('sysparm_name','MandatoryVariables');
ga.addParam('sysparm_value', g_form.getValue('request_item')); //send RITM number
ga.getXML(ajaxResponse);
}
}
function ajaxResponse(serverResponse) {
var result = serverResponse.responseXML.getElementsByTagName("result");
var message = result[0].getAttribute("message");
if(message){
alert(message);}
var output = "";
var variables = serverResponse.responseXML.getElementsByTagName("variable");
for (i=0; i < variables.length ; i++){
//g_form.setMandatory(variables[i],false);
var name = variables[i].getAttribute("name");
output += name + "\n" ;
}
alert(output);
}
Script include:
var mandatoryVariables = Class.create();
mandatoryVariables.prototype = Object.extendsObject(AbstractAjaxProcessor, {
MandatoryVariables: function(){
var result = this.newItem("result");
result.setAttribute("message", "returning mandatory variables");
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(this.getParameter('sysparm_value'));
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
if(vs.get(i).mandatory==true){
this._addVariable(vs.get(i).getName());
}
}
},
_addVariable : function(name) {
var vars = this.newItem("variable");
vars.setAttribute("name", name);
},
type: 'mandatoryVariables'
});