- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 05:07 AM
There is oob widget "sp-variable-editor". I have cloned it and used it in CSM case page in portal.
suppose, we raise case via record producer with 20 variables filled out of 50 variables.
Problem is that it is showing all 50 variables in variable editor, requirement is to only show which is not empty(filled ones)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 05:46 AM
in that cloned widget update these 2 functions getValuesForProducer() and getValues() present in server side
function getValues(table, sys_id, task_id, opened_by) {
var qs = new GlideappVariablePoolQuestionSet();
if (table == "sc_cart_item")
qs.setCartID(sys_id);
else if (table == "sc_task") {
qs.setRequestID(sys_id);
qs.setTaskID(task_id);
} else {
qs.setRequestID(sys_id);
}
qs.load();
var values = {};
var questions = qs.getFlatQuestions().toArray();
for (var i = 0; i < questions.length; i++) {
var q = questions[i];
if (q.getValue()) {
var o = {
value: q.getValue(),
displayValue: q.getDisplayValue(),
type: q.getType()
};
//handling List Collector (21) and Masked (25) variables.
if (o.type == 21)
o.display_value_list = q.getDisplayValues().toArray();
if (o.type == 25 && q.canDecrypt(opened_by, table))
o.decrypted_value = q.decrypt(o.value);
var qKey = q.getName();
if (typeof qKey == 'undefined' || qKey == '')
qKey = "IO:" + q.getId();
values[qKey] = o;
}
}
return values;
}
function getValuesForProducer(table, sys_id, opened_by) {
var qs = new GlideappSequencedQuestionSet();
qs.setTableName(table);
qs.setTableSysID(sys_id);
qs.load();
var values = {};
var questions = qs.getFlatQuestions().toArray();
for (var i = 0; i < questions.length; i++) {
var q = questions[i];
if (q.getValue()) {
var o = {
value: q.getValue(),
displayValue: q.getDisplayValue(),
type: q.getType()
};
//handling List Collector (21) and Masked (25) variables.
if (o.type == 21)
o.display_value_list = q.getDisplayValues().toArray();
if (o.type == 25 && q.canDecrypt(opened_by, table))
o.decrypted_value = q.decrypt(o.value);
var qKey = q.getName();
if (typeof qKey == 'undefined' || qKey == '')
qKey = "IO:" + q.getId();
values[qKey] = o;
}
}
return values;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2025 11:21 PM
only show the filled variables in the "sp-variable-editor" widget, you can modify the widget's script to filter out empty variables. Here's a quick approach:
Modify the widget script: Before rendering, filter the variables to display only the non-empty ones. var filledVariables = [];
for (var i = 0; i < data.variables.length; i++) {
if (data.variables[i].value) {
filledVariables.push(data.variables[i]);
}
}
Update the widget: Use the filledVariables array to display only the variables with values.
This way, only the variables that are filled out will be shown in the editor.