Reference 'Text' instead of 'Value' for 'Select Box' variable type in Record Producer

Carl Fransen1
Tera Guru

Hi Team,

Hopefully an easy one as I can't see why this won't work for me.

I have a Record Producer with a number of variables and when I submit the form I want to grab a few variables and copy to the description field.  This works for all variables, but for the 'Select Box' it shows the 'value' and not the 'text'.

To grab the variable in the script are I enter the following:

current.description = 'Course Provider: ' + producer.u_course_provider.  This works for all variables

For the course providers I have entered these in the  following format:  Text 'Company A' and the value is 'company_a'.

I can't seem to refer to the 'text' and all I get back is the 'value' - so the value of 'company_a' but I need 'Company A' as it's the friendly name I need to show in the description field.

I haven't entered the 'value' as the 'friendly name, with spaces and caps' as my understanding is that this isn't the recommended way to enter stored values.  I could rename all my 'values' to the same as the 'text' - but before I did this I need to confirm that this won't cause any issues.  The product documentation isn't clear if this is the correct way of adding question choices or nor?

Can anyone help with this?

1 ACCEPTED SOLUTION

Joe F1
Kilo Expert

Hey Carl, I'm probably too late here but I just came across your post as I was experiencing the same challenge due to a requirement I have to make our select box question choices differ between the text and value.

I tried a lot of different things from what I'd seen on the community and in ServiceNow documentation, but it turned out Sanjiv was very close in giving you the correct answer.

Instead of this: producer.u_course_provider.getDisplayValue();

It should be this: producer.getDisplayValue('u_course_provider');

Here's how I'm handling my record producer output:

producer.getDisplayValue('u_course_provider'); //provides the choice text - friendly display

producer.u_course_provider; //provides the choice value 

producer.u_course_provider.getGlideObject().getQuestion().getLabel(); //provides the field label if you don't want to hardcode the label in your RP output

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

There wont be any problem using Company A as value instead of company_a. if it is a variable name, there shouldn't be a space.

 

Or Did you try using producer.u_course_provider.getDisplayValue();

 

 


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

Thanks for the reply - I did try the getdisplayvalue previously, this broke it and it just showed nothing....

I'm starting to think changing the value might be the asiest, but there must be a way to reference the text instead....

I usually populate the description post submission of the record producer.

I use the below script

(function executeRule(current, previous /*null when async*/) {
	
	var desc = '';
	var qtype = 0;
	var q = new GlideRecord('question_answer');
	q.addQuery('table_sys_id',current.sys_id);
	q.orderBy('order');
	q.query();
	
	while (q.next())
		{
		if (q.value!='' && q.value!='false' || q.question.type==11)
			{
			
			if (q.question.type==11)
				desc = desc+'\n';
			
			
			if (q.question.type!=7)
				{
				if (desc=='')
					desc = q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
				else
					desc = desc+'\n'+q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
			}
			else
				{
				if (qtype==7)
					desc = desc+','+q.question.getDisplayValue();
				else
					desc = desc+' '+q.question.getDisplayValue();
			}
			
			qtype = q.question.type;
		}
		
		if (q.question.type==19)
			desc = desc+'\n';
	}
	
	if (desc!='')
		current.description = desc;
	
})(current, previous);

function getRefValue(type,table,value)
{
	if (type==8)
		{
		var ref = new GlideRecord(table);
		ref.get(value);
		
		return ref.getDisplayValue();
	}
	else
		{
		return value;
	}
}

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

Thanks for the assistance and the script - Not sure how this would grab a different value from the questions in my 'select box' but I will give this a try to see how it works for me.

 

Thanks

Carl.