- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 01:10 PM
Hello all,
I have a Client Script that I am using to try to add a button next to a variable, called "Requested By". NOTE: The variable is within a variable set.
function onLoad() {
try{
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
var varControl = form.getControl("requested_by").id;
$(varControl).insert({
after: '<span><a id="icon-check-circle" class="btn btn-default sc-ref-spacer icon-check-circle sn-tooltip-basic" title="" data-original-title="Check availability"></a></span>'
});
}
catch(e){
alert(e.message);
}
}
Ideally, the button would appear here, inside the Variables, that's why I am trying to add it via Client Script.
I am currently getting this error message:
Any ideas or suggestions?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 05:33 AM
Oh man, oh man, I swear I do my best programming in the morning!! 😃
Here is the result, a button that pulls of the related Requested Items, based on the "requested by" variable, WITHIN the variables collection. This will work for every service catalog item that has a "requested_by" variable (which is most of them) and DOES NOT require a change/update to each service catalog item.
Modal window of Related Request Items by Requested For user
Client Script code:
function onLoad() {
try{
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
var varControl = "lookup." + form.getControl("requested_by").id;
if(varControl)
{
$(varControl).insert({
after: '<span><a onclick="showRelatedRequestItems()" id="icon-check-circle" class="btn btn-default sc-ref-spacer icon-tree-right sn-tooltip-basic" title="" data-original-title="Show related Request Items"></a></span>'
});
}
}
catch(e){
alert(e.message);
}
}
//onclick event to fire when the button is clicked
function showRelatedRequestItems() {
try {
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
var displayValue = g_form.getDisplayBox("requested_by").value;
var title = 'Showing Requested Items for: ' + displayValue;
var query = 'request.requested_for=' + form.getValue("requested_by");
var gdw = new GlideModal('show_list');
gdw.setTitle(title);
gdw.setSize(750);
gdw.setPreference('table', 'sc_req_item_list');
gdw.setPreference('sysparm_query', query);
gdw.render();
} catch (e) {
jslog('error showing related list');
jslog(e);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 01:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 01:20 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 04:48 AM
Isolate script is checked. For the purposes of the script, should it be on or off?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 04:40 PM
Hi Matt,
Have you considered using a UI Macro / Macro variable to show the button? It can be hidden / shown based on UI policies, you won't even need DOM manipulation using client scripts. You just need to create a UI Macro, and associate it with a Macro variable in your catalog item. That UI macro can have the HTML code, and the javascript / jQuery logic for the button.
But if you want to use your client script to add that button, as already suggested change Isolate Script value to False; and try changing "$" to "$j" or "jQuery", i.e.
$(varControl).insert
to
$j(varControl).insert
or
jQuery(varControl).insert
"$" operator is used in jelly, that's why for jQuery you would have to use $j or jQuery as the operator.
Hope this helps!
Cheers,
Manish