Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get Display Value of Reference field when default value is not set.

patbishop
Mega Guru

I am attempting to pass Service Catalog variables from one RITM to another (via ebonding), however, one of the Packages that I was using to accomplish this, GlideappAbstractChoiceListQuestion, is not available within a scoped application. Does anyone know an alternative?

Essentially, I am pulling data from the sc_item_option_mtom table, which is working, but if the data returned is referenced from another table (sys_user, cmn_location, etc) it is only showing the Sys_ID, instead of a friendly Display Value.

Below is an example of a simple script that can be run in Scripts - Background. This WILL work in Global Scope, but I get: "Error: GlideappAbstractChoiceListQuestion is not allowed in scoped applications" if run in my scope.

var varown = new GlideRecord('sc_item_option_mtom');
	varown.addQuery("request_item", 'SYS_ID HERE');
	varown.addQuery("sc_item_option.item_option_new.type","NOT IN","12,20,24,19");
	varown.orderBy("sc_item_option.order");
	varown.query();
	while (varown.next()){
		var visible = varown.sc_item_option.item_option_new.visible_summary;
		var question = GlideappAbstractChoiceListQuestion.getQuestion(varown.sc_item_option.item_option_new);
		question.setValue(varown.sc_item_option.value);
		
			if(question.getDisplayValue() != ""){
                                
				gs.print('Question:'+question.getLabel());
                                gs.print('Variable Name:'+question.name);
                                gs.print('Value:'+question.getDisplayValue() + '\n\n');
			}	
		} 
1 ACCEPTED SOLUTION

One more correction

var item = new GlideRecord('sc_req_item');
item.addQuery('number','RITM0010001');
item.query();

if (item.next())
{
gs.info(item.number);
var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery('request_item', item.sys_id+'');
//varown.addQuery("sc_item_option.item_option_new.type","NOT IN","12,20,24,19");
varown.orderBy("sc_item_option.order");
varown.query();
while (varown.next())
{
//gs.info(varown.sc_item_option.item_option_new);
var visible = varown.sc_item_option.item_option_new.visible_summary;
if(varown.sc_item_option.item_option_new.getDisplayValue() != "" && typeof item.variables[varown.sc_item_option.item_option_new.name]!='undefined')
{ gs.info('Question:'+varown.sc_item_option.item_option_new.getDisplayValue()+' : '+item.variables[varown.sc_item_option.item_option_new.name].getDisplayValue());
}
}

}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

18 REPLIES 18

varown.sc_item_option.item_option_new.getDisplayValue()

 

holds the question


Please mark this response as correct or helpful if it assisted you with your question.

I am trying to get the Display Value of the VALUE field. I can get the Question field just fine. The VALUE field will show a Sys_ID unless a default display value is posted on the table, which there isn't and I cannot change.

Try this. This will print both Question and display values of the answers.

 

        var set = new GlideappVariablePoolQuestionSet();

          set.setRequestID(current.sys_id);// requested item sys_id

          set.load();

          var vs = set.getFlatQuestions();

          for (var i=0; i < vs.size(); i++) {

              if(vs.get(i).getLabel() != '' && JSUtil.notNil(vs.get(i).getDisplayValue()) ) {

                          wn+= vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + "\n";

              }

}

gs.print('variables and values are '+wn);


Please mark this response as correct or helpful if it assisted you with your question.

This is the same issue I have with my original code. It does not run under a scoped application:

Evaluator: java.lang.SecurityException: GlideappVariablePoolQuestionSet is not allowed in scoped applications Caused by error in script at line 1 ==> 1: var set = new GlideappVariablePoolQuestionSet();

I tested below and it works fine in my instance. try and let me know if it works for you.

 


var item = new GlideRecord('sc_req_item');
item.addQuery('number','RITM0010001');
item.query();

if (item.next())
{
gs.info(item.number);
var varown = new GlideRecord('sc_item_option_mtom');
varown.addQuery('request_item', item.sys_id+'');
//varown.addQuery("sc_item_option.item_option_new.type","NOT IN","12,20,24,19");
varown.orderBy("sc_item_option.order");
varown.query();
while (varown.next())
{
//gs.info(varown.sc_item_option.item_option_new);
var visible = varown.sc_item_option.item_option_new.visible_summary;
if(varown.sc_item_option.item_option_new.getDisplayValue() != "")
{ gs.info('Question:'+varown.sc_item_option.item_option_new.getDisplayValue()+' : '+item.variables[varown.sc_item_option.item_option_new.name]);
}
}

}


Please mark this response as correct or helpful if it assisted you with your question.