When working with incident record producers, it’s common to want all the user’s responses added into the ticket’s Work Notes or Comments field.
But normally, that means manually fetching each variable one by one — a task that’s easy to forget to update when new variables are added later.
Here’s a small, reusable code snippet that loops through all the variables on a Record Producer automatically, and adds them to the work notes. It also excludes unwanted types like containers or labels, so only meaningful answers are included. Replace SYSID_HERE with the correct sys_id for your record producer.
// Initialize Worknotes
var worknotes = '';
// Query the variables associated with the record producer
// and exclude unneeded variable types
var gr = new GlideRecord('item_option_new');
gr.addEncodedQuery('cat_item=SYSID_HERE^type!=19^type!=14^type!=20^type!=32^question_text!=wizard_page');
gr.orderBy('order');
gr.query();
// Iterate through all the variables and add them to the worknotes variable
// This way we don't need to manually fetch each one
while (gr.next()) {
var var_name = gr.getValue('name').toString(); // Variable name
var var_label = gr.getValue('question_text').toString(); // Variable label
var var_answer = producer[var_name].getDisplayValue();
if (var_answer && var_answer != '' && var_answer != 'undefined') {
worknotes += var_label + '\n';
worknotes += var_answer + '\n\n';
}
}
current.work_notes = worknotes;
This can easily be adapted to save it into another field, or used for a different ticket type (although incident is probably the most common use case!)
How It Works
Querying Variables
The script uses item_option_new to find all variables linked to the Record Producer (using its sys_id in cat_item).
Excluding Non-Data Variables
Certain variable types (like labels, containers, and macro variables) don’t contain user input. The addEncodedQuery call filters these out with type!=... conditions.
Looping Automatically
For each variable, the script:
- Gets its internal name (to fetch the value from the producer object)
- Gets its label (to make the output readable)
- Gets the user’s answer using
getDisplayValue() - Appends the results to
worknotes
Updating Work Notes
Finally, it writes the full collected string to the current.work_notes field, so all variable responses are stored in the target record.



