Variable Editor Expand/Collapse Capability

MB26
ServiceNow Employee
ServiceNow Employee

If you use the Variable Editor on your task forms (incident, change request items, etc.) you are aware that they are not collapsable. Depending on the amount of variables you have from your record producer or request item etc, this may result in a large portion of the displayed form. I have given the ability to expand, collapse these variables. I have even set a "startopen" variable (true/false) to determine if you want this variable editor expanded or collapse upon page load.

Interestingly enough there is really only 1 constant id that I can find in this variable editor. So I used the prototypejs DOM traversal functions using this id as the base. This does mean that if Service-Now ever modifies the HTML format of this variable editor, this may not continue to work. For now it is pretty cool.

Here is how it works:
Just to start, here is the general idea of what the variable editor looks like, for those not too familiar with it (below). It is the similar form that was created in a record producer, request item etc.
find_real_file.png

I created a single client script to run onload. You can create this on the Incident, Request Item, etc. tables, or wherever you use the variable editor, to work for you.



function onLoad() {

if ($('variable_map')){
var startopen = 'true';
var variables = $('variable_map').up(1);
var items = variables.nextSiblings();
var cline = $('variable_map').up(1).previous('tr').down('td');

if (startopen == 'false'){
mytoggler();
cline.setStyle({backgroundImage:"url(images/section_hide.gifx)", backgroundRepeat:'no-repeat', backgroundPosition:'99% 50%'});
}
else {
cline.setStyle({backgroundImage:"url(images/section_reveal.gifx)", backgroundRepeat:'no-repeat', backgroundPosition:'99% 50%'});
}

cline.observe('click', mytoggler);
}
function mytoggler() {
for (var i = 0; i < items.length; i++){
var item = items<i>;
if (item.inspect().indexOf('<script>item.toggle();

if(item.visible()){
cline.setStyle({backgroundImage:"url(images/section_reveal.gifx)", backgroundRepeat:'no-repeat', backgroundPosition:'99% 50%'});
} else {
cline.setStyle({backgroundImage:"url(images/section_hide.gifx)", backgroundRepeat:'no-repeat', backgroundPosition:'99% 50%'});
}
}
}
}
}


Here are some simple screenshots of how it looks when applied.
First, the client script adds the same collapse icon to the right.
find_real_file.png

When clicked the variables collapse and the icon changes to the same expand icon.
find_real_file.png

9 REPLIES 9

Bill_Collins
Mega Guru

Great script. Thank you. Are the icons reversed? -Bill


hetalvadanlal
Tera Contributor

Hi

For calgary variable_map is undefined. IS there any workaround for this?

Regards
Hetal


Gagan10
Giga Contributor

is this still working, as trying to implement the same but not working 

Ishan Bajaj
Giga Expert

Hello All,

Is this script working in any recent release i.e. Orlando and further releases. I tried this but it didn't work. Can anyone help on this?

Jeffrey Barton
Tera Contributor

I found an elegant solution - Just put the "Variable Editor" into it's own section on the form.  That contains it to a tab.
I put the title on the tab as "User Form Input Details" but you can call it what you want.