How can I make the short description field be auto filled with a variable answer in a record producer? I need the Text, not value displayed in the Short description field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 11:13 AM
We have a scoped HR app in our instance and have a requirement to auto fill the short description field with what was selected in one of the variables (Learning Category). I was able to partially make it work by using the "Map to field" checkbox. However, the value that is being displayed is the "value" instead of the "Text".
Can you please advise how I can make it point to the Text column?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 12:36 PM
You may use below code piece to assign the variable display value rather than variable internal value to the current record getting created when you submit record producer.
current.short_description = producer.getDisplayValue("short_description")

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 12:53 PM
sorry for the follow up question, where should I put that code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 01:29 PM
"script" field in the "What it will contain" tab of the record producer.
producer object refers to the variables on record producer form.
And current object refers to the record which is getting created.
If you want to transform the inputs, you need to perform that logic in the script field and make sure that you are assigning the necessary values to current record fields.
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 01:40 PM
I am a little late to the party but here is a Business Rule (Before) we created for a client to copy all the variables to the description for Record Producers. It is not complete. Depending on the field types that you need other than these: Reference, List collector, Select Box , Single and Multiple Line Text. Also it takes care of empty variables.
(function executeRule(current, previous /*null when async*/ ) {
var type, name, value, reference, val, item;
var producerVars = new GlideRecord('question_answer');
producerVars.addQuery('table_sys_id', current.sys_id);
//Exclude Label and Container variables
producerVars.addQuery('question.type', '!=', 11);
producerVars.addQuery('question.type', '!=', 19);
producerVars.addQuery('question.type', '!=', 20);
// Set Order
producerVars.orderBy('order');
producerVars.query();
var descriptionBuilder = '';
while (producerVars.next()) {
if (producerVars.value) {
//Add variable names and values to the description
type = producerVars.question.type.toString();
name = producerVars.question.question_text.toString();
val = producerVars.value.toString();
// Reference
if (type == 8 ) {
reference = producerVars.question.reference.toString();
value = getReferenceDisplayValue(reference, val);
descriptionBuilder += (name + ": " + value + "\n");
}
// Select Box
else if (type == 5) {
item = producerVars.question.sys_id;
value = getChoiceDisplayValue(item, val);
descriptionBuilder += (name + ": " + value + "\n");
}
// List Collector
else if (type == 21) {
var valSplit = val.split(',');
var arr = [];
for (i = 0; i < valSplit.length; i++) {
value = getChoiceDisplayValueList(valSplit[i]);
arr.push(value);
arr.join(',');
}
descriptionBuilder += (name + ": " + arr + "\n");
}
// Default
else {
value = val;
descriptionBuilder += (name + ": " + val + "\n");
}
// Replace blank values with
if (value == '') {
value = '';
}
}
}
current.description = descriptionBuilder;
// Function to convert reference value to display value
function getReferenceDisplayValue(table, value) {
var displayValue1 = '';
var gr1 = new GlideRecord(table);
gr1.addQuery('sys_id', value);
gr1.query();
if (gr1.next()) {
displayValue1 = gr1.getDisplayValue();
}
return displayValue1;
}
// Function to convert choice value to display value
function getChoiceDisplayValue(item_option, value) {
var displayValue2 = '';
var gr2 = new GlideRecord('question_choice');
gr2.addEncodedQuery('question=' + item_option + '^value=' + value);
gr2.query();
if (gr2.next()) {
displayValue2 = gr2.text + '';
}
return displayValue2;
}
// Function to convert choice value to display value for List Collector
function getChoiceDisplayValueList(value) {
var displayValue2 = '';
var gr2 = new GlideRecord('question_choice');
gr2.addEncodedQuery('sys_id=' + value);
gr2.query();
if (gr2.next()) {
displayValue2 = gr2.text + '';
}
return displayValue2;
}
})(current, previous);