How to add a button to the Requested Item form?

Matt Cordero1
Tera Guru

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.

find_real_file.png

I am currently getting this error message:

find_real_file.png

 

Any ideas or suggestions?

 

1 ACCEPTED SOLUTION

Matt Cordero1
Tera Guru

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.

find_real_file.png

Modal window of Related Request Items by Requested For user

find_real_file.png

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);
}
}

View solution in original post

5 REPLIES 5

Matt Cordero1
Tera Guru

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.

find_real_file.png

Modal window of Related Request Items by Requested For user

find_real_file.png

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);
}
}