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

SanjivMeher
Kilo Patron
Kilo Patron

Did you try global.GlideappAbstractChoiceListQuestion ?


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

The Error I get when prefixing it with global is "Evaluator: java.lang.SecurityException: Invalid object in scoped script: [JavaClass com.glideapp.questionset.AbstractChoiceListQuestion]"

Why not just try this?

 

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; if(varown.sc_item_option.item_option_new.getDisplayValue() != ""){ gs.print('Question:'+varown.sc_item_option.item_option_new.getDisplayValue()); } }

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

The "varown.sc_item_option.value" is the one that contains the Sys_ID, not the Question field.

"Value" is the name of the field on the table.