- 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,220 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
ā01-14-2020 12:24 PM
Hi,
This is great.
On my instance, first part of the onload script works only if fieldname is the first variable of the section.
In this case the section is collapsed
But we can't expand it. Click event does not work.
Any idea ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-08-2020 03:26 AM
This method was working completely fine in service portal. Any idea why this is getting applied in the Native UI variable editor also?Because it is not behaving as expected.
Also I've unchecked apply to target record in ui policy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-25-2021 12:58 PM
Oleg, I'm trying to use your Client Script but it is not working. I'm on Orlando. Is there something I need to do different with the script since I'm in Orlando??
Brandon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-25-2021 01:38 PM
Hi Brandon!
I tried to reproduced the same code on Quebec and on Orlando Patch 10 Hot Fix 1 instances and on both the code worked without any problem. Please verify that you exactly followed my instructions:
- created Container Start, which has "Display title" checked and Container End
- added Catalog Client Script, which I posted. The script must have "UI Type" to work on
- verify the line fieldName = "requested_for", which I marked in my code with "// !!!". The fieldName value should contains the name of some variable from the current variable set.
If the code still will not work you should add "debugger;" statements in the code end debug it in Developer Tools of your web browser. It should help to find, which pert of the code works incorrectly any why.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-25-2021 02:26 PM