- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-17-2019 02:35 AM
Hi Folk,
I have a requirement in the service catalog variable to make a container as a collapse in the service portal. I know this functionality available in native view through a variable set it's working fine but this is not working as the collapse in service portal. Please see the below SS:
1. In a native view:
2. In service Portal view:
Guy's is there any solutions so, please share to me.
Thanks In Advance
PKG
Solved! Go to Solution.
- 18,251 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-17-2019 07:11 AM
One can add mission collapsing button by DOM manipulation inside of Client Script.
First of all, one should create Start and End containers in the variable set to make the block collapsible in Desktop environment. You did the step already. I just insert screenshot to show that one need the name of one variable later, which is inside of the block:
In the above example I'll use later the name of variable requested_for later in Catalog Client Script. The start container looks for example like the following:
Now you can add the following Catalog Client Script:
function onLoad () {
var $ = this.jQuery,
fieldName = "requested_for"; // !!! it's the name of any variable from variable set !!!
setTimeout(function () {
var $fieldset = $("#sp_formfield_" + fieldName).closest("fieldset"),
$row = $fieldset.children("div.row"),
$button = $("<button style='margin-right:10px;margin-bottom:2px;' class='btn btn-icon'>" +
"<i class='fa fa-plus fa-lg'></i></button>");
$fieldset.find("legend") // find(">div>legend")
.prepend($button);
// one can comment the line if one don't want collapse the
$row.hide();
$button.click(function () {
$row.toggle();
$button.find("i")
.toggleClass("fa-plus fa-minus");
});
}, 0);
}
which should be executed onLoad on Service Portal:
The script finds <fieldset> element, which exists on Service Portal and which enclose all variables. The code prepends collapsing button before the field set and binds small onclick event handler which toggle the fieldset. As the result one get results like on the picture below:
with button, which can be used for collapsing. If one want to have expended initial state (like on Desktop version) then the code need be modified in 2 lines to the following
function onLoad () {
var $ = this.jQuery,
fieldName = "requested_for"; // !!! it's the name of any variable from variable set !!!
setTimeout(function () {
var $fieldset = $("#sp_formfield_" + fieldName).closest("fieldset"),
$row = $fieldset.children("div.row"),
$button = $("<button style='margin-right:10px;margin-bottom:2px;' class='btn btn-icon'>" +
"<i class='fa fa-minus fa-lg'></i></button>");
$fieldset.find("legend") // find(">div>legend")
.prepend($button);
$button.click(function () {
$row.toggle();
$button.find("i")
.toggleClass("fa-plus fa-minus");
});
}, 0);
}
In above code the class in $button is replaced from fa-plus to fa-minus and the line $row.hide() is removed.
One can of cause customize the collapse/expend button in different way by adding title attribute, changing the style and so on. For example, adding "font-size:12px;padding:.4em .6em;background-color:transparent;color:#848a91; border:1px solid #848a91;" to the the style="margin-right:10px;margin-bottom:2px;" one will get the look of the button close to the the look on the desktop (classical UI).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-08-2022 02:44 AM
Hi Oleg,
My instance just got upgraded from Paris to Rome and I was using the code posted 3 years ago with fieldset tag. But now after upgrade it isn't working, if I try your Rome code it is populating but I have few more customization which is getting crashed on using the Rome code. So could you please help me how can I make the use of old code using fieldset tag and make it working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-08-2022 03:53 AM
Sorry Deepika,
you posted too few information about your problem. I can't reproduce the problem having such information. I can only guess. You can try to use
jQuery("sp-variable-layout fieldset>legend").closest(".sp-form-container")
instead of
$("sp-variable-layout>fieldset>legend")
The full code could be close to the following:
function onLoad () {
var $ = this.jQuery;
setTimeout(function () {
var $row = $("sp-variable-layout fieldset>legend").closest("div.row"),
$container = $row.closest(".sp-form-container"),
$button = $("<button style='margin-right:10px;margin-bottom:2px;' class='btn btn-icon'>" +
"<i class='fa fa-minus fa-lg'></i></button>");
$container.find("legend") // find(">div>legend")
.prepend($button);
$button.click(function () {
$row.toggle();
$button.find("i")
.toggleClass("fa-plus fa-minus");
});
}, 0);
}
If the code will not help you then I would recommend you to post new question with code, which can be used to reproduce your problem. If you would post the reference to new question to me I will try to help you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-08-2022 04:28 AM
Hi Oleg,
Thanks for your response but this didn't help. I have posted the question in community
So can you please help me with same ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-21-2022 10:09 AM
I use this code in our environment and it's helpful to see the changes when the versions change.
Thank you very much for keeping this updated for us who don't know DOM manipulation like myself. I adjusted the code for my instance and it works again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā04-23-2022 12:52 PM
Hello everyone,
I am migrating to the San Diego version and I have use Oleg last update script for "Rome" to apply the code on a Variable Set "Catalog Client Scripts".
However, I have a small difference to the orginal script I used since the collapse button is now on top of the container start of the variable set which is not very nice for a user experience since before it was just on the left side of the container title.
+ the script is executed for all the containers of my catalog item which counts 3 different containers.
Does anyone have a solution to make the collapse button on the same line with the container title and also to be executated for each containers individually?
Thank you for all your helps on this.
Michel