Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
detlev_beutner
Active Contributor
0 Kudos

Lately I got the order to implement a FlexUI command to copy the KM GUID (the "short ID") into the windows clipboard just by one click. The use case was quite valid: If one wants to paste links to a certain KM resource into other documents or into a mail for example, it is a muddle to create this. The official way takes many clicks if using the standard Details command: Details - Settings - Properties - Access Links - mark & copy the Short ID -- this for example results in "/guid/508c546c-736f-2a10-efa2-8662ff5ffd80"; and then mark & copy the beginning of the Explorer URL to fetch the first part of the URL, which then for example is "http://localhost:50000/irj/go/km/navigation". Putting both parts together creates the address one was looking for - all but user friendly, isn't it?

So I started to develop the command, and at a certain point, I just wanted to have a look at the SAP source code to access the short ID programmatically (it's often faster to look at the original code then to use the JavaDoc). Doing so, I stumbled over a property renderer which was offering just what I wanted to implement - it is offering a link beneath the rendered short ID to copy the URL into the clipboard. Having seen this, I thought that if somebody has implemented this property renderer, the corresponding command can't be far away -- and that was the case 🙂

Both features are undocumented, and I'm also unsure how "old" they are. From the information I got from my customer as well as from my local portal installation, it seems to be provided with SPS20 on NW '04 (which corresponds to SPS12 on NW 7.0); the implementing class names partially don't follow the standard naming conventions, so maybe some details will change when these features will be made officially available. Screenshots following are taken from SPS13 on NW 7.0.

 

Property Renderer Offering a Copy to Clipboard Link


The aforementioned Short ID property within the Access Links properties group technically is represented by the standard property cm_rnd_shortID which is rendered by the property renderer rnd_shortID. But there is one additional property maintained (but not put into the default property groups) with a different property renderer: cm_rnd_shortID_copy, rendered by rnd_shortID_copy_s. And there is even one more property renderer rnd_shortID_copy. Lets have a look at these:

The additional property of course is not a "real" property but is just a dummy property serving as a placeholder to bring the property renderer into the game. It is no problem just to use the different property renderers for the original property (which in turn is also just a placeholder, as the GUID is created bythe UriMapperService, and not a real property of a KM resource).

Here are the results of the different renderers. First the rnd_shortID_copy, which renders the Short ID as usual but with an additional link to copy the GUID-URL into the clipboard:

The rnd_shortID_copy_s renderer only renders the link and leaves out the ID itself:


The Copy to Clipboard Command


Beneath the possibility to render the standard property with an additional or simply as  a "Copy Short ID to Clipboard" link, there is also an equivalent command offered, which is very user friendly, as it reduces the click rate massively (you don't need to go via Details - Settings - Properties - Acccess Links any more).

The name of this command is "copy_urlTo_clipboard", and it isn't part of any command group within the standard delivery (yet). One good place in my opinion could be the SingleDetailsGroup command group, which is used quite often to offer access to the details of a resource. To test the command, you could just alter this standard command group and add ",copy_urlTo_clipboard" into the groups command list:

With that, you can call for example a navigation iView with the AdminExplorer layout set, et voilà, the command appears, and pressing it it seems not to do anything - as it does its job in the background, copying the full URL into the windows clipboard:

CTRL-V in this case pastes for example http://localhost:50000/irj/go/km/navigation/guid/508c546c-736f-2a10-efa2-8662ff5ffd80.


The Logic of Determining the URL

 

  1. External links are used "as is", so no GUID comes into the game. If a KM link points to http://www.google.com, exactly this value will be in the clipboard.
  2. Internal links are resolved, so the URL within the clipboard does not point to the link resource but to the resource targeted by the link; see 3. and 4. also for the target resource and how it is handled.
  3. For KM collections (folders) the URL points to the navigation component (as it can be seen in the example above).
  4. For "real" KM resources (no link, no collection, but some kind of document) the URL points to the docs component, so that calling the URL would bring up the document itself.


The Magic Behind


Pasting some text from IE-JS into the clipboard is really trivial: window.clipboardData.setData('Text', theTextToBePasted)

Doing the same for Mozilla / Firefox is much more a hassle; there are security constraints to consider, and the coding is all but short or intuitive. A first overview is given on developer.mozilla.org. A different approach using some Flash file is announced by Jeffrey Larson, very interesting.

Anyhow, SAP has implemented the pure JS approach (see http://www.krikkit.net/howto_javascript_copy_clipboard.html for the template SAP used) and the best is: It is rendered by the WdfProxy class, somewhat the "heart" of the FlexUI framework. So, if you want to implement any kind of "Copy some stuff to clipboard" command or renderer link, all you have to call is the JS function copy_clip(theTextToBePasted)! Happy clipboarding 🙂

6 Comments
Labels in this area