Comments on: Hide Empty Variables on a Standard Form https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/ ServiceNow Consulting Scripting Administration Development Thu, 07 Mar 2024 15:43:01 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: Kevin M https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8733 Mon, 30 Apr 2018 13:16:13 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8733 This part of the code can cause a slow query:

var producerVars = new GlideRecord(‘question_answer’);
producerVars.addQuery(‘table_sys_id’, current.sys_id);

There is an index on questions_answer ( table_name, table_sys_id, order ) that is not used because table_name is not being used, but it is available, and can be used to speed up this business rule:

var producerVars = new GlideRecord(‘question_answer’);
producerVars.addQuery(‘table_name’, current.sys_class_name); // ADD THIS LINE TO USE EXISTING INDEX
producerVars.addQuery(‘table_sys_id’, current.sys_id);

]]>
By: Mila Morales https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8732 Tue, 19 Sep 2017 11:37:39 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8732 In reply to Albert Tagle.

Hi Albert,
You can’t do this using this script. Instead, you can create a UI Policy and make the variables not visible and apply it only to the target record.

]]>
By: Dale https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8731 Tue, 12 Sep 2017 08:21:31 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8731 In reply to Jim Pisello.

I sourced my Business Rule from a different blog but took some inspiration from your idea to hide ‘false’ checkboxes (type = 7) Here is the script of my BR:

hideEmptyFields();
function hideEmptyFields() {
var emptyVars = [];
var v;
/* Put all variable values and labels from the variable pool into an array */
for (var i in current.variables) {
v = current.variables[i];
/* Only include empty variables, and exclude Label and Container variables */
if (v == ” && v.getGlideObject().getQuestion().type != 11 && v.getGlideObject().getQuestion().type != 19 && v.getGlideObject().getQuestion().type != 20 || (v.getGlideObject().getQuestion().type == 7 && v.getGlideObject().getValue() == ‘false’)) {
emptyVars.push(v.getGlideObject().getQuestion().getName());
}
}
/* Join the variable values together into a string */
g_scratchpad.emptyVars = emptyVars.join(‘,’);
// gs.log(‘BR – RITM Variables for ‘ + current.number + ‘: ‘ + g_scratchpad.emptyVars);
}

]]>
By: Albert Tagle https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8730 Thu, 10 Aug 2017 06:13:02 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8730 Hi,

In addition to empty variables, is it also possible to hide specific variables? – In a record producer, I have created several read-only single line texts variables, these texts contain instructions to redirect users to contact somebody else depending on what they have selected in the questions, but these will not make any value to the ticket handler, so I would like to hide these specific variables from the variable editor.

Thanks!

]]>
By: Jim Pisello https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8729 Thu, 13 Jul 2017 14:19:37 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8729 In reply to Ashley Pyle.

Hi Ashley,

Unchecked check box variables actually have a value of false. They are only ’empty’ from a visual standpoint. Because they have a value, even unchecked check boxes will appear when using this solution. You could exclude all check box variables from the list by modifying the two queries in the code to account for variables with a value of false. Adding a lines like

itemVars.addQuery('sc_item_option.value', false);

and

producerVars.addQuery('value', false);

to the appropriate queries in the code might work.

]]>
By: Ashley Pyle https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8728 Thu, 06 Jul 2017 11:36:44 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8728 Just implemented this script into our test environment and works quite well (Helsinki Patch 11) expect for check boxes, empty check boxes still remain?

]]>
By: Mark Stanger https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8727 Wed, 26 Apr 2017 17:51:18 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8727 In reply to Jakub Pobiecky.

This is just for standard forms. I don’t have anything for service portal like this currently.

]]>
By: Jakub Pobiecky https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8726 Wed, 26 Apr 2017 14:59:22 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8726 Hello Mark,
Thanks for the script, it works pretty well on backend. But I have an issue, when I show the form in the Service Portal. The client script is not working. As I saw in the docs, variables.name notation is not supported in Service Portal. Also when I try to simply log in client script g_form.getValue(varName) or g_form.getValue(‘variables.’ + varName), both values are empty. It seems like client script doesn’t see variables. Did you make your solution work in Service Portal? Thanks a lot

]]>
By: Masoom Sharma https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8725 Fri, 21 Apr 2017 18:27:08 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8725 It worked from Global Application :). Variables belong to global application so script is accessing on global then it worked.

]]>
By: Masoom Sharma https://servicenowguru.com/client-scripts-scripting/hide-empty-variables-standard-form/#comment-8724 Fri, 21 Apr 2017 04:23:32 +0000 https://servicenowguru.wpengine.com/?p=3826#comment-8724 Thanks for your response Mark

]]>