Since OpenUI release, browser console became a powerful tool in hands of confident Siebel developer. In this topic I'll give you an idea how to organise your browser code snippets and will share couple of examples how to take an advantage of SiebelApp object.
Traditional way of injecting browser code.
How to run: F12 => Console tab => type the command or use up key to flip through history => enter
SiebelApp.S_App.GetActiveView().GetActiveApplet().GetName();
Useful if you need to store more than oneliners.
How to run: F12 => Source tab => Snippets => right click => run
Here is an example why you might need it.
console.log(SiebelApp.S_App.GetActiveView().GetName());
var am = SiebelApp.S_App.GetActiveView().GetAppletMap();
for (sAppletName in am) {
console.log('\t' + sAppletName + '(' + am[sAppletName].GetBusComp().GetName() + ')');
}
Easiest way to run a code snippet. It is not only takes one click to run your code but it also allows 'endless' features (fancy UI, working with clipboard, history of queries). I see bookmarklets as an open source, cross-browser, cross-environment Siebel plugin. If you manage to use Chrome code snippets to build and debug snippets and then compile them into bookmarklets.
I usually use Chrome snippets as a source code vault and as GUI to build and debug my code. Once the code is stable, I make it a bookmarklet and enjoy it.
How to create: Linearise your JS code, remove comments or simply minify it (for example, JSCompress or JS/CSS Minifier, thanks Emma!), escape quotes and finally wrap it with "javascript:{...};void(0)". Here is how the code from above example will look like as a bookmarklet:
javascript:{var s=SiebelApp.S_App.GetActiveView().GetName();var am=SiebelApp.S_App.GetActiveView().GetAppletMap();for(sAppletName in am){s+='\n\t'+sAppletName+'('+am[sAppletName].GetBusComp().GetName()+')';}alert(s);};void(0)
You can always use online bookmarklet converters. Here are couple examples:
How to install: Easiest way is to drag & drop a link on your favourites toolbar. I'm a bookmarklet Drag & Drop me. Here is a full article on how to install bookmarklets for different browsers.
How to run: Click
Check out how powerful and convenient bookmarklets could be:
/*
@desc fancy UI wrapper for GetProfileAttr Siebel function
@author VB(xapuk.com)
@version 1.1 2018/06/08
*/
if ("undefined" == typeof SiebelApp) {
alert("It works only in Siebel OUI session!");
}
// snippet id
var id = "SiebelProfileAttr";
// localStorage to store the history
var aHist = window.localStorage[id] ? JSON.parse(window.localStorage[id]) : [];
// just in case (experimental)
$("#" + id).parent().remove();
// constructing dialog content
var s = '<div title="Get Profile Attribute">';
s += '<input id = "' + id + '" type="text" list="' + id + 'List" style="width:100%" value="' + (aHist.length ? aHist[0] : "") + '">';
s += '<datalist id="' + id + 'List">';
for (var i = 0; i < aHist.length; i++){
s += '<option>' + aHist[i] + '</option>';
}
s += '</datalist>';
s += '<input id="' + id + 'Out" type ="text" style="display:none">';
s += '<ul></ul></div>';
// open dialog
var $d = $(s).dialog({
modal: true,
width: 640,
open: function() {
$('#' + id).focus().select(); // autofocus
},
close: function() {
$(this).dialog('destroy').remove();
},
buttons: [{
text: 'Get (Enter)',
click: go
}, {
text: 'Close (Esc)',
click: function() {
$(this).dialog('close');
}
}]
});
listHistory();
function go() {
var name = $d.find('#' + id).val();
if (name) {
// moving recent query to the top
if (aHist.indexOf(name) > -1) {
aHist.splice(aHist.indexOf(name), 1);
}
aHist.unshift(name);
window.localStorage[id] = JSON.stringify(aHist);
//rerender history
listHistory();
}
return name;
}
// print a list of recent queries
function listHistory() {
var $ul = $d.find("ul").empty();
for (var i = 0; i < aHist.length && i < 5; i++) {
// five recent values
$ul.append('<li><b>' + aHist[i] + '</b> = <a href="#">' + SiebelApp.S_App.GetProfileAttr(aHist[i]) + '</a></li>');
}
// copy value on click
$d.find("a").click(function(event) {
var val = $(this).html();
$("#" + id + "Out").show().val(val).select();
var r = document.execCommand("copy");
$("#" + id + "Out").hide();
if(r){
$(this).hide().after('<span id="tmp" style="color:red">Copied!</span>');
setTimeout(function(){
$d.find("a").show();
$d.find("#tmp").remove();
}, 500);
}
});
}
// key bindings
$d.keyup(function(event) {
// enter
if (event.keyCode === 13) {
go();
}
});
/*
@desc fancy wrapper for GotoView Siebel function
@author VB(xapuk.com)
@version 1.0 12/06/2018
*/
if ("undefined" == typeof SiebelApp){
alert("It works only in Siebel OUI session!");
}
// snippet id
var id = "SiebelGotoView";
// localStorage to store the history
var aHist = window.localStorage[id]?JSON.parse(window.localStorage[id]):[];
// just in case (experimental)
$("#" + id).parent().remove();
// constructing dialog content
var s = '<div title="Goto View">';
s += '<input id = "' + id + '" type="text" list="' + id + 'List" style="width:100%" value="' + (aHist.length?aHist[0]:"") + '">'; // most recent
s += '<datalist id="' + id + 'List">';
for (var i =0; i < aHist.length; i++){ // full history into unbounded picklist
s += '<option>' + aHist[i] + '</option>';
}
s += '</datalist><ul>';
for (var i =0; i < aHist.length && i < 5; i++){ // five recent values as links
s += '<li><a href="#">' + aHist[i] + '</a></li>';
}
s += '</ul></div>';
// open dialog
var $d = $(s).dialog({
modal: true,
width: 640,
open: function() {
$('#' + id).focus().select(); // autofocus
},
close: function() {
$(this).dialog('destroy').remove();
},
buttons: [{
text: 'Go (Enter)',
click: function(){
go($d.find('#' + id).val());
}
}, {
text: 'Close (Esc)',
click: function() {
$(this).dialog('close');
}
}]
});
// GotoView
function go(name) {
if (name){
// moving recent view to the top
if (aHist.indexOf(name) > -1){
aHist.splice(aHist.indexOf(name),1);
}
aHist.unshift(name);
window.localStorage[id] = JSON.stringify(aHist);
$d.dialog('close');
SiebelApp.S_App.GotoView(name); //running GotoView command
}
}
// running GotoView on Enter
$d.keyup(function(event) {
// enter
if (event.keyCode === 13) {
go($d.find('#' + id).val());
}
});
// running GotoView on link click
$d.find("a").click(function(event) {
go($(this).html());
});