As most of you know, Service Portal has a pretty handy context menu that you can access by simply holding down CTRL and clicking (right click on PC) on a widget. The context menu provides several shortcuts to some of the frequently used configuration options.
Note: the “sp_admin” role is required to see the context menu.
Adding custom context menu items
But did you know you can also add your own options to the list?
Open up the Widget Editor and insert the following JavaScript into the Client Script field.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function($scope, $window, i18n) { var c = this; c.widget._debugContextMenu = [ // Open instance in platform [ "1. Configure Menu Options", function(){ $window.open("/sp_instance_menu.do?sys_id="+c.data.menu_id); }], // Supports label translation [ i18n.getMessage("2. Translate Me"), function() { $window.open("/sp_config"); }], // External Link [ "3. Link to Google", function(){ $window.open("http://google.com"); }] ]; } |
Now when you view the widget in the portal and you open the context menu, you will see your newly configured menu items.
Sounds very interesting! Thank you for that hint!
Can anyone explain to me what i18n.getMessage does? I see that it is injected in to the Client Controller.
Can it be used similar to gs.getMessage to translate messages? It seams to be a synchronous function, right?
i18n is shorthand for internationalization. I believe this service performs similarly to the server side gs.getMessage().
Is there any way to get a custom menu like this for a widget inside a widget?
E.g. a widget within a Macro variable on a catalog item
Whenever I log the $scope or $scope.data it always relates to the scope of the entire catalog item, and I have to fish through all the variables to find my particular widget.
I don’t think this is possible. You would need to add the options to the parent widget and then pass it through to the embedded widget.
Hi ,
Its very interesting. Awesome info. Same way is it possible to add approve , resolve, reject options as well.. like when user clicks resolve then it should resolve the incident .. same way for approve, reject?
Hi this is great information
Which Client script is being used to display this right click menu?
Tx